Reputation: 4409
How to set UIColor
value into CGContextSetRGBStrokeColor
// This is red color which i set to the CGContextSetRGBStrokeColor
CGContextSetRGBStrokeColor(contextRef, 1, 0, 0,1.00f);
Now i do have UIColor which has RGB value i need to set this value to CGContextSetRGBStrokeColor
.
Any one suggest me how to set UIColor
value's CGContextSetRGBStrokeColor
Upvotes: 7
Views: 5545
Reputation: 572
In swift 3.0
let context = UIGraphicsGetCurrentContext()
context!.setStrokeColor(red: 1,green: 1,blue: 1,alpha: 1)
Or you can ser color as below
context!.setStrokeColor(UIColor.red.cgColor)//or any UIColor
Upvotes: 0
Reputation: 54953
For the lazy :
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
Upvotes: 1
Reputation: 7612
Alternative:
CGContextSetStrokeColorWithColor(context, [[UIColor greenColor] CGColor]);
// or
[[UIColor colorWithRed:1.0f green:0.0f blue:0.0f alpha:1.0f] CGColor];
Upvotes: 14
Reputation: 28409
CGFloat red, green, blue, alpha;
[color getRed:&red green:&green blue:&blue alpha:&alpha];
CGContextSetRGBStrokeColor(contextRef, red, green, blue, alpha);
Upvotes: 9