首页 > 编程语言 > 详细

SwiftUI 渐变色

时间:2020-04-10 23:54:43      阅读:143      评论:0      收藏:0      [点我收藏+]
  • 渐变探索
// 线性渐变
LinearGradient(gradient: Gradient(colors: [.red,.green]), startPoint: UnitPoint.topLeading, endPoint: UnitPoint.bottomTrailing)
            .frame(width: 200, height: 200)
// 角度渐变
AngularGradient(gradient: Gradient(colors: [.red,.green]), center: UnitPoint.center).frame(width: 200, height: 200)

// 半径渐变
RadialGradient(gradient: Gradient(colors: [.red,.green]), center: UnitPoint.center, startRadius:1, endRadius: 100)
            .frame(width: 200, height: 200)    }

LinearGradien:

使用LinearGradien绘制线形颜色渐变的背景。 示例代码:

Text("SwifUI Gradient")
    .font(.system(size: 36))
    .padding()
    .foregroundColor(.white)
    .background(LinearGradient(gradient: Gradient(colors: [.orange, .red, .purple]), startPoint: .topLeading, endPoint: .bottomTrailing))

}

AngularGradient:

使用AngularGradient绘制角度颜色渐变的背景。 示例代码:

VStack{
    Text("SwifUI Gradient")
    .font(.system(size: 36))
    .padding()
    .foregroundColor(.white)
    .background(AngularGradient(gradient: Gradient(colors: [.orange, .red, .purple]), center: UnitPoint(x: 0.5, y: 0.5), angle: Angle.init(degrees: -45)))

    Text("SwifUI Gradient")
    .font(.system(size: 36))
    .padding()
    .foregroundColor(.white)
    .background(AngularGradient(gradient: Gradient(colors: [.orange, .red, .purple]), center: UnitPoint(x: 0.5, y: 0.5), startAngle: Angle.init(degrees: 0), endAngle: Angle.init(degrees: 0)))

}

RadialGradient:

使用RadialGradient绘制径向颜色渐变的背景。 示例代码:

Text("SwifUI Gradient")
    .font(.system(size: 36))
    .padding()
    .foregroundColor(.white)
    .background(RadialGradient(gradient: Gradient(colors: [.orange, .red, .purple]), center: .init(x: 0.5, y: 0.5), startRadius: CGFloat(10), endRadius: CGFloat(120)))

}

SwiftUI 渐变色

原文:https://www.cnblogs.com/liuxiaokun/p/12676824.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!