cgcolor

iOS - Setting UIButton background color only colors the corners

ぐ巨炮叔叔 提交于 2019-11-30 17:30:51
I'm trying to customize my button by changing their colors, but when I use either: self.loginButton.layer.backgroundColor = [UIColor colorWithRed:0.0 green:157.0/255.0 blue:223.0/255.0 alpha:1.0].CGColor; or self.loginButton.backgroundColor = [UIColor colorWithRed:0.0 green:157.0/255.0 blue:223.0/255.0 alpha:1.0]; All I get is this result: What I want to do is change the white color to blue, any idea what I'm doing wrong? You're using a round rect button which is pretty ugly, and pretty hard to customise. You can create a custom type button and use a background image, or create a custom type

iOS - Setting UIButton background color only colors the corners

那年仲夏 提交于 2019-11-30 01:14:57
问题 I'm trying to customize my button by changing their colors, but when I use either: self.loginButton.layer.backgroundColor = [UIColor colorWithRed:0.0 green:157.0/255.0 blue:223.0/255.0 alpha:1.0].CGColor; or self.loginButton.backgroundColor = [UIColor colorWithRed:0.0 green:157.0/255.0 blue:223.0/255.0 alpha:1.0]; All I get is this result: What I want to do is change the white color to blue, any idea what I'm doing wrong? 回答1: You're using a round rect button which is pretty ugly, and pretty

How to get color components of a CGColor correctly

眉间皱痕 提交于 2019-11-29 19:30:27
问题 I have a UILabel with black color; i am writing the following code to get black color's components. UIColor *aColor = [aLabel.textColor retain]; const CGFloat* components = CGColorGetComponents(aColor.CGColor); CGColorSpaceRef colorSpace=CGColorSpaceCreateDeviceRGB(); but always this is giving Green color components instead of black color components; Is any one have idea about this? Am i passing different color space? :-( Please help me. 回答1: Most likely wrong colorspace. I guess the alpha

How to convert colors from one color space to another?

故事扮演 提交于 2019-11-29 09:13:50
Is there a Cocoa Touch way to convert colors from one color space to another? At the end of this code: UIColor *grey = [UIColor colorWithWhite: 0.5 alpha: 1.0]; CGColorRef greyRef = [grey CGColor]; int x = CGColorGetNumberOfComponents(greyRef); ... x is 2. The reason I need this is I'm trying to copy colors to a list of color components for CGGradientCreateWithColorComponents , which needs all colors in a single colorspace. The problem is that grey is in the grayscale colorspace, rather than the RGB one. (The name escapes me at the moment, but it isn't important.) CGGradientRef createGradient

How to compare two UIColor which have almost same shade or range in iOS?

与世无争的帅哥 提交于 2019-11-28 18:27:55
I have a condition in my app where user can choose 3 colors, but those colors should not match with each other, the problem is user can choose the similar color from the pallet for all 3 fields. I'm trying below code, here color2 has slightly different value of 'green' than color1 :- UIColor *color1 = [UIColor colorWithRed:1 green:(CGFloat)0.4 blue:1 alpha:1]; UIColor *color2 = [UIColor colorWithRed:1 green:(CGFloat)0.2 blue:1 alpha:1]; if ([color1 isEqual:color2]) { NSLog(@"equals"); }else { NSLog(@"not equal"); } output: 'not equal' This is correct by logic because it compares RGB value but

Extracting rgb from UIColor [duplicate]

◇◆丶佛笑我妖孽 提交于 2019-11-28 16:36:52
This question already has an answer here: How to get RGB values from UIColor? 14 answers Seen this asked before but my example does not seem to work. const CGFloat *toCol = CGColorGetComponents([[UIColor greenColor] CGColor]); The array is empty from looking at it with GDB. Any hints? The code sample you provided should work. Try this: UIColor uicolor = [[UIColor greenColor] retain]; CGColorRef color = [uicolor CGColor]; int numComponents = CGColorGetNumberOfComponents(color); if (numComponents == 4) { const CGFloat *components = CGColorGetComponents(color); CGFloat red = components[0];

How to match UIExtendedSRGBColorSpace to my color values

落花浮王杯 提交于 2019-11-28 08:04:17
问题 I set the color for UIButton with the XCode visual editor. I set it using RGB sliders. Then I set variable green : let green = UIColor(red: 0, green: 210/255, blue: 0, alpha: 1) When I printed out green value and UIButton.backgroundColor I got next values accordingly: UIExtendedSRGBColorSpace -0.146119 0.836984 -0.0130851 1 UIExtendedSRGBColorSpace 0 0.823529 0 1 So, as I guess, the color spaces are equal, but values are not. Why is it so? The Apple's UIButton() does some hidden conversion?

How to convert colors from one color space to another?

自作多情 提交于 2019-11-28 02:36:55
问题 Is there a Cocoa Touch way to convert colors from one color space to another? At the end of this code: UIColor *grey = [UIColor colorWithWhite: 0.5 alpha: 1.0]; CGColorRef greyRef = [grey CGColor]; int x = CGColorGetNumberOfComponents(greyRef); ... x is 2. The reason I need this is I'm trying to copy colors to a list of color components for CGGradientCreateWithColorComponents , which needs all colors in a single colorspace. The problem is that grey is in the grayscale colorspace, rather than

How to compare two UIColor which have almost same shade or range in iOS?

浪尽此生 提交于 2019-11-27 11:21:32
问题 I have a condition in my app where user can choose 3 colors, but those colors should not match with each other, the problem is user can choose the similar color from the pallet for all 3 fields. I'm trying below code, here color2 has slightly different value of 'green' than color1 :- UIColor *color1 = [UIColor colorWithRed:1 green:(CGFloat)0.4 blue:1 alpha:1]; UIColor *color2 = [UIColor colorWithRed:1 green:(CGFloat)0.2 blue:1 alpha:1]; if ([color1 isEqual:color2]) { NSLog(@"equals"); }else {

Extracting rgb from UIColor [duplicate]

孤街醉人 提交于 2019-11-27 09:48:46
问题 This question already has an answer here: How to get RGB values from UIColor? 15 answers Seen this asked before but my example does not seem to work. const CGFloat *toCol = CGColorGetComponents([[UIColor greenColor] CGColor]); The array is empty from looking at it with GDB. Any hints? 回答1: The code sample you provided should work. Try this: UIColor uicolor = [[UIColor greenColor] retain]; CGColorRef color = [uicolor CGColor]; int numComponents = CGColorGetNumberOfComponents(color); if