SwiftUI from entry to actual combat Chapter 2 Section 14: AngularGradient

Related courses: http://hdjc8.com/hdjc/swiftUI/

Use AngularGradient to draw a background with an angular color gradient. This lesson demonstrates the use of angle gradients. Angle gradient refers to the fan-shaped gradient of the color from the starting point to the end point in a clockwise direction, that is, the emission-shaped gradient.

Sample code:

VStack{
    Text("SwifUI Gradient")//首先修改此处的文本视图,角度渐变将作为文本视图的背景。
    .font(.system(size: 36))//设置文本视图的字体尺寸为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)))

}

View the results of the operation:

Guess you like

Origin blog.csdn.net/fzhlee/article/details/106244208