ios – 如何在Swift中更改UIBezierPath的颜色?

ios – 如何在Swift中更改UIBezierPath的颜色?,第1张

概述我有一个UIBezierPath的实例,我想将笔画的颜色改为黑色以外的东西.有谁知道如何在斯威夫特这样做? 使用 Swift 3,UIColor具有 setStroke()方法. setStroke()具有以下声明: func setStroke() Sets the color of subsequent stroke operations to the color that the recei 我有一个UIBezIErPath的实例,我想将笔画的颜色改为黑色以外的东西.有谁知道如何在斯威夫特这样做?解决方法 使用 Swift 3,UIcolor具有 setStroke()方法. setstroke()具有以下声明:
func setstroke()

Sets the color of subsequent stroke operations to the color that the receiver represents.

因此,您可以使用这样的setstroke():

strokecolor.setstroke() // where strokecolor is a `UIcolor` instance

下面的游乐场代码显示了如何在UIBezIErPath旁边使用setstroke(),以便在UIVIEw子类中绘制一个绿色填充颜色和浅灰色笔画颜色的圆圈:

import UIKitimport PlaygroundSupportclass MyVIEw: UIVIEw {    overrIDe func draw(_ rect: CGRect) {        // UIBezIErPath        let newRect = CGRect(            x: bounds.minX + ((bounds.wIDth - 79) * 0.5 + 0.5).rounded(.down),y: bounds.minY + ((bounds.height - 79) * 0.5 + 0.5).rounded(.down),wIDth: 79,height: 79        )        let ovalPath = UIBezIErPath(ovalIn: newRect)        // Fill        UIcolor.green.setFill()        ovalPath.fill()        // stroke        UIcolor.lightGray.setstroke()        ovalPath.linewidth = 5        ovalPath.stroke()    }}let myVIEw = MyVIEw(frame: CGRect(x: 0,y: 0,wIDth: 200,height: 300))PlaygroundPage.current.liveVIEw = myVIEw
总结

以上是内存溢出为你收集整理的ios – 如何在Swift中更改UIBezierPath的颜色?全部内容,希望文章能够帮你解决ios – 如何在Swift中更改UIBezierPath的颜色?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1097169.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存