50ButtonsEach / fliclib-ios

The fliclib framework for iOS
35 stars 5 forks source link

How to get a color value of the button? #16

Closed dukhanov closed 8 years ago

dukhanov commented 8 years ago

I have two buttons (Black and White), and I am trying to get color of the buttons:

NSString *colorString = [CIColor colorWithCGColor:button.color.CGColor].stringRepresentation;
NSLog(@"colorString: %@", colorString);

And I receive string representation of color:

colorString1: 1 1 0 1
colorString1: 0.156863 1 0 1

Description from Apple docs https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/QuartzCoreFramework/Classes/CIColor_Class/index.html#//apple_ref/occ/instm/CIColor/stringRepresentation:

Discussion The string representation always has four components—red, green, blue, and alpha. The default value for the alpha component is 1.0. For example, this string:

@"0.5 0.7 0.3 1.0"

These values do not look like white or black:

colorString1: 1 1 0 1
colorString1: 0.156863 1 0 1

How I can get the correct color value of a button?

dukhanov commented 8 years ago

On Android platform, I can get color name of the button:

button.getColor() // "white", "yellow" and etc

Is it possible to implement the same logic as on Android?

AntonMeier commented 8 years ago

This is actually a bug in the flic app that parses the color wrong. It has been fixed and will be available as on the next Flic App update on App Store that should arrive in about a week or so. Regarding using UIColor or color strings, I personally feel that it is better to get the color directly rather than have to parse a string value. Otherwise all apps using the SDK would have to be updated in case we add new button colors in the future.

dukhanov commented 8 years ago

Got it. Thanks for quick response.