uicolor

Detecting if UIColor was created with colorWithPatternImage

旧巷老猫 提交于 2020-01-24 11:34:31
问题 I have a UIColor that is passed into me. I need to detect if it is a plain color (e.g. created with colorWithRed:green:blue:alpha: ) or if it is a color that was created with colorWithPatternImage . How can I tell what kind of color a UIColor is, simple color or otherwise? 回答1: You should be able to use the CGColorGetPattern function with the CGColor property, and check for NULL . if( CGColorGetPattern( myColor.CGColor ) != NULL ) {} 回答2: Another solution is to check the color space model: if

iOS App crashes when using colorWithRed:green:blue:alpha

雨燕双飞 提交于 2020-01-15 11:18:08
问题 I have a UIControl subclass in my iOS App (I'm using iOS 4.3), and part of the subclass is a method called "setButtonColor:(UIColor)bc". Whenever I call this method from my code, it works fine...but only if I use a built-in color like greenColor or redColor. If I use " colorWithRed:green:blue:alpha ," to make my own color it crashes with this message in the console: -[UIDeviceRGBColor set]: message sent to deallocated instance 0x4e61560 Here's the setButtonColor: method: -(void)setButtonColor

How to make one colour transparent in UIImage

梦想的初衷 提交于 2020-01-10 19:53:29
问题 I want to change a colour in UIimage to transparent I am using below code to change black colour to transparent -(void)changeColorToTransparent: (UIImage *)image{ CGImageRef rawImageRef = image.CGImage; const float colorMasking[6] = { 0, 0, 0, 0, 0, 0 }; UIGraphicsBeginImageContext(image.size); CGImageRef maskedImageRef = CGImageCreateWithMaskingColors(rawImageRef, colorMasking); { CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 0.0, image.size.height); CGContextScaleCTM

HEX to UIColorfromRGB

醉酒当歌 提交于 2020-01-07 02:51:28
问题 I'm following a tutorial here It's fairly straight forward and simple, only 2 steps. But on the last step, I have the HEX code in a UITextField as hexText.text, but how do i put that into UIColorFromRGB? 回答1: here is a solution that avoids the macro stuff. You can add it to a category to UIColor and use it more nicely. 回答2: Sorin has the right idea here I think. Much more cocoa-like, and will result in fewer headaches. To answer your question at a high level, you'd need to convert your string

Comparison of UIColors

大城市里の小女人 提交于 2020-01-03 18:54:32
问题 I have some code which I can't figure out why it's not working, UIColor *lastColor, *red; red = [UIColor colorWithRed:0.993 green:0.34444 blue:0.0 alpha:1.0]; NSString *chosenColor; if([lastColor isEqual: red]) { chosenColor = @"red"; } I have also found some people making an override of the isEqual method, isEqualtoColor: But this didn't work either and i fed that one lastColor.CGColor; Everywhere I've read that isEqual is all you need to compare the UIColors, im currently resorting to an

Comparison of UIColors

房东的猫 提交于 2020-01-03 18:53:16
问题 I have some code which I can't figure out why it's not working, UIColor *lastColor, *red; red = [UIColor colorWithRed:0.993 green:0.34444 blue:0.0 alpha:1.0]; NSString *chosenColor; if([lastColor isEqual: red]) { chosenColor = @"red"; } I have also found some people making an override of the isEqual method, isEqualtoColor: But this didn't work either and i fed that one lastColor.CGColor; Everywhere I've read that isEqual is all you need to compare the UIColors, im currently resorting to an

Get MidColor from UIColor

六月ゝ 毕业季﹏ 提交于 2020-01-03 05:13:26
问题 I was looking for sample which gives me mid colour from passed UIColor. In the following Example, Get Slightly Lighter and Darker Color from UIColor can get lighter & darker colour from UIColor. But i need to get average/ mid colour from UIColor. Anyone help me to solve this? Thanks in Advance. 回答1: The code to which you point steps the colour up or down by 0.2 in the first code example and adjusts brightness in the second. By mid-colour I assume you mean one of two things: (1) the colour

UITableViewCell Content View - Adding UILabels

你。 提交于 2020-01-02 08:34:18
问题 I currently have the following code for my cellForRowAtIndexPath on my UITableView: - (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString* CellIdentifier = @"Cell"; UILabel* nameLabel = nil; UILabel* valueLabel = nil; UILabel *percentLabel = nil; UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier]; if ( cell == nil ) { inthere = YES; cell = [[[UITableViewCell alloc] initWithStyle:

how can I pass UIColor's name

寵の児 提交于 2020-01-02 07:37:27
问题 I want to know that how can I pass UIColor's name to the specific method ? EDIT : - (id) setLabel:(NSString *)text WithColorName:(NSString *)nameOfColor FontName:(NSString *)f_name FontSize:(float)f_size abel:(UILabel *)templbl { templbl.backgroundColor = [UIColor ?????]; return templbl; } any suggestions ? Thanks.. 回答1: NSString *colorStr = @"magenta"; NSString *selectorString = [colorStr stringByAppendingString:@"Color"]; SEL selector = NSSelectorFromString(selectorString); UIColor *color =

UIColor with pattern image and color behind

淺唱寂寞╮ 提交于 2020-01-01 19:21:39
问题 I am trying to set the background color of some UIView element. I would like to paint it with blue color and a dash pattern on top. I know I could make a new UIView as its child and paint it with [UIColor colorWithPatternImage:pattern] but I would specifically want one UIView , so get one UIColor with blue background and pattern image on top. Marko EDIT : Pattern image is like this : And the result should be : 回答1: - (UIImage *)image:(UIImage *)image withColor:(UIColor *)color { CGSize