Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Set UIColor Value To CGContextSetRGBStrokeColor

Tags:

iphone

ipad

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

like image 282
kiran Avatar asked Apr 16 '12 14:04

kiran


3 Answers

Alternative:

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

// or
[[UIColor colorWithRed:1.0f green:0.0f blue:0.0f alpha:1.0f] CGColor];
like image 162
Roger Avatar answered Nov 17 '22 00:11

Roger


CGFloat red, green, blue, alpha;
[color getRed:&red green:&green blue:&blue alpha:&alpha];
CGContextSetRGBStrokeColor(contextRef, red, green, blue, alpha);
like image 9
Jody Hagins Avatar answered Nov 17 '22 01:11

Jody Hagins


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

like image 1
Matthieu Riegler Avatar answered Nov 17 '22 01:11

Matthieu Riegler