SwiftUI(3) Drawing and Animation
程序员文章站
2022-03-16 15:13:47
...
参考
动画
形状
1.矩形
Rectangle().frame(width: 200, height: 200)
2.圆角矩形
RoundedRectangle(cornerRadius: 30)
.frame(width: 200, height: 200)
3.圆形
Circle().frame(width: 200, height: 200, alignment: .center)
4.椭圆
Ellipse().frame(width: 200, height: 100, alignment: .center)
5. 胶囊
Capsule().frame(width: 200, height: 100, alignment: .center)
![胶囊](https://img-blog.csdnimg.cn/20191204161322815.png)
画笔,样式,渐变
1. 颜色
//color也继承于View,可以当做view使用
//通过已定义的颜色创建
Color.red.frame(width: 200, height: 200)
//通过rgb创建,rgb为百分比,如果是0-255之间的数字,则要除以255
Color(red: 1, green: 0.4, blue: 1,opacity: 0.5).frame(width: 200, height: 200)
//通过十六进制数创建
参考:https://blog.csdn.net/weixin_43864837/article/details/88619823
Color(UIColor.colorWithHex(hexStr: "#eeeeee")).frame(width: 200, height: 200)
2. 渐变
//线性渐变
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) }