如何将UIColor值设置为CGContextSetRGBStrokeColor

时间:2012-04-16 14:34:19

标签: iphone ipad

如何将UIColor值设置为CGContextSetRGBStrokeColor

//这是我设置为CGContextSetRGBStrokeColor的红色     CGContextSetRGBStrokeColor(contextRef,1,0,0,1.00f);

现在我的UIColor有RGB值我需要将此值设置为CGContextSetRGBStrokeColor

任何人都建议我如何设置UIColorCGContextSetRGBStrokeColor

4 个答案:

答案 0 :(得分:14)

替代:

CGContextSetStrokeColorWithColor(context, [[UIColor greenColor] CGColor]);

// or
[[UIColor colorWithRed:1.0f green:0.0f blue:0.0f alpha:1.0f] CGColor];

答案 1 :(得分:9)

CGFloat red, green, blue, alpha;
[color getRed:&red green:&green blue:&blue alpha:&alpha];
CGContextSetRGBStrokeColor(contextRef, red, green, blue, alpha);

答案 2 :(得分:1)

懒惰:

let myUIColor = UIColor.purpleColor()
var r:CGFloat, g:CGFloat, b:CGFloat, a:CGFloat = 0
myUIColor.getRed(&r, green: &g, blue: &b, alpha: &a)
CGContextSetRGBStrokeColor(c, r, g, b, a)

// or 
CGContextSetStrokeColorWithColor(myUIColor.CGColor);

#SwiftStyle

答案 3 :(得分:0)

在swift 3.0中

return new JtaTransactionManager(); } Either way, the end result in a JavaEE application server is that you can now use JTA to manage

或者您可以使用以下颜色

let context = UIGraphicsGetCurrentContext()
context!.setStrokeColor(red: 1,green: 1,blue: 1,alpha: 1)