- [UICIColor colorSpaceName]: unrecognized selector sent to instance

I create several classes to support themes in my iOS 5 application. My themes are stored in plist and I load them into Theme object which I use in my application to initialize various controls. I store the colors as strings in my theme, and then I use this code to convert them to UIColor:

UIColor* color = [UIColor colorWithCIColor:[CIColor colorWithString:@"0.5 0.5 0.5 1.0"]]; 

This works great for most controls, however, when I try to set the hue of the navigation bar as such:

 //navigation bar [self.navigationController.navigationBar setTintColor:color]; 

I get this exception:

 -[UICIColor colorSpaceName]: unrecognized selector sent to instance 

When I initialize the color without using CIColor, for example. eg:

 UIColor* color = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:1.0]; [self.navigationController.navigationBar setTintColor:color]; 

Everything works great.

Any clues what causes this? I could not find much information about UICIColor, but I assume that UIColor is just a shell on top of CGColor or CIColor, there are differences in implementation.

+4
source share
3 answers

See Strange crash when trying to access titleLabel uibutton property (xcode 4.5 and iOS sdk 6.0)

I found a workaround: before using my colorWithCIColor, I made a copy of it with:

 newcolor = [UIColor colorWithCGColor:newcolor.CGColor]; 

and this solves the problem. Strange anyway

+3
source

I had similar problems with

 [UIColor colorWithCIColor:[CIColor colorWithString:color]]; 

Although I was looking for an elegant solution for this, in the end, I decided to solve the problem, which stopped the problem and turned on my application so that it continues exactly the same as before.

My color string was in the same format as yours:

 "0.5 0.7 0.2 0.75" 

I found the easiest way to fix this was to simply do the following:

 NSArray * colorParts = [color componentsSeparatedByString: @" "]; CGFloat red = [[colorParts objectAtIndex:0] floatValue]; CGFloat green = [[colorParts objectAtIndex:1] floatValue]; CGFloat blue = [[colorParts objectAtIndex:2] floatValue]; CGFloat alpha = [[colorParts objectAtIndex:3] floatValue]; UIColor * newColor = [UIColor colorWithRed:red green:green blue:blue alpha:alpha]; 

Manually separate each value and then insert it into the colorWithRed: code.

This means that you can save your color bar, but get rid of the problematic colorWithString code that causes all the crashes.

Hope this helps

+1
source

UIColor in iOS 2.0 , due to [UIColor colorWithCIColor] convert to iOS5.0 , I think the apple conversion error, you can use the code below:

  CIColor *ci_ = [CIColor colorWithString:colorString]; UIColor *color = [UIColor colorWithRed:ci_.red green:ci_.green blue:ci_.blue alpha:ci_.alpha]; // UIColor *color = [UIColor colorWithCIColor:[CIColor colorWithString:colorString]]; 
-1
source

Source: https://habr.com/ru/post/1434325/


All Articles