swift渐变_如何在Swift中使用渐变进度创建UIProgressView

swift渐变_如何在Swift中使用渐变进度创建UIProgressView

2023年7月14日发(作者:)

swift渐变_如何在Swift中使⽤渐变进度创建UIProgressViewswift 渐变I am an iOS engineer, and last week I was converting a UI design into a screen on Xcode's interface builder, when I faced thislayout:我是⼀名iOS⼯程师,上周,当我遇到以下布局时,我将UI设计转换为Xcode的界⾯⽣成器上的屏幕:So, the designer wanted a progress view containing a gradient fill, and this is how I built it on code:因此,设计⼈员想要⼀个包含渐变填充的进度视图,这就是我在代码上构建它的⽅式:First of all, I've created a UIImage extension to initiate it with an array of UIColor, which will be turned into a gradient. Also, Icreated a GradientOrientation enum to specify if the gradient is vertical or horizontal. This way, we can use the UIImage init inother UI components, such as UIImageView.⾸先,我创建了⼀个UIImage扩展,以使⽤UIColor数组启动它,它将被转换为渐变。 另外,我创建了⼀个GradientOrientation枚举来指定渐变是垂直还是⽔平。 这样,我们可以在其他UI组件(例如UIImageView使⽤UIImage初始化。Finally I've created the GradientProgressView, a class extended from UIProgressView which contains firstColor and variables were marked as IBInspectable, so they can be assigned at the Interface Builder. By changing these colorseither on storyboard or on code, the progress view's progressImage will be set as a gradient starting at firstColor and ending atsecondColor.最后,我创建了GradientProgressView ,从扩展⼀个类UIProgressView包含firstColor和secondColor 。 这些变量被标记为IBInspectable,因此可以在Interface Builder中对其进⾏分配。 通过改变这些颜⾊或者在故事板或代码,进度视图的progressImage将被设置为⼀个梯度起始于firstColor和在结束secondColor 。That being done, we just need to change the GradientProgressView's first and second colors and

voilà, our progress views arenow gradient-ready.完成后,我们只需要更改GradientProgressView的第⼀和第⼆种颜⾊和voilà ,我们的进度视图就可以进⾏渐变了。Gradient progress view examples渐变进度视图⽰例swift 渐变

发布者:admin,转转请注明出处:http://www.yc00.com/news/1689264879a226442.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信