gpt4 book ai didi

swift - 如何为使用核心图形制作的形状添加自定义颜色?

转载 作者:行者123 更新时间:2023-11-28 13:13:15 25 4
gpt4 key购买 nike

我用核心图形制作了一个形状,我想用自定义颜色填充它。例如,我想要深红色而不是默认的红色。

这是形状和颜色的代码:

override func drawRect(rect: CGRect) {

let context = UIGraphicsGetCurrentContext()
CGContextSetLineWidth(context, 3.0)
CGContextSetStrokeColorWithColor(context, UIColor.redColor().CGColor)


CGContextMoveToPoint(context, 50, 50)
CGContextAddLineToPoint(context, 90, 130)
CGContextAddLineToPoint(context, 180, 100)
CGContextAddLineToPoint(context, 90, 60)
CGContextAddLineToPoint(context, 50, 50)

CGContextStrokePath(context)

CGContextSetFillColorWithColor(context, UIColor.redColor().CGColor)
CGContextFillPath(context)
}

最佳答案

请尝试阅读文档并自己解决问题。你是说:

UIColor.redColor()

如果那不是你想要的颜色,通过调用

UIColor(red:r, green:g, blue:b, alpha:a)

...其中 rgba 是 CGFloat 值。

关于swift - 如何为使用核心图形制作的形状添加自定义颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30399142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com