SwiftUI 颜色渐变填充效果 (教程含源码)

SwiftUI 为我们提供了各种梯度选项,所有这些选项都可以通过多种方式使用。

Gradient 渐变器

A color gradient represented as an array of color stops, each having a parametric location value.

gradient是一组颜色的合集,每个颜色都忽略位置参数

LinearGradient 线性渐变器

线性渐变器拥有沿轴进行渐变函数,我们可以自定义设置颜色空间、起点和终点。

下面我们看看LinearGradient效果
LinearGradient

import SwiftUI

struct LineView: View {
     var gradient: Gradient {
           let stops: [Gradient.Stop] = [
               .init(color: .red, location: 0.5),
               .init(color: .yellow, location: 0.5)
           ]
           return Gradient(stops: stops)
       }
       
       var body: some View {
       
               ZStack {
        

猜你喜欢

转载自blog.csdn.net/iCloudEnd/article/details/108450354