Re: Missing something with CGColorGetComponents()
Re: Missing something with CGColorGetComponents()
- Subject: Re: Missing something with CGColorGetComponents()
- From: Laurent Daudelin <email@hidden>
- Date: Thu, 14 Oct 2010 13:57:44 -0700
On Oct 14, 2010, at 12:32, Conrad Shultz wrote:
> On 10/14/10 10:58 AM, Laurent Daudelin wrote:
>> My first foray in Quartz and I'm having some problems, obviously
>> missing something.
>>
>> Given the following code in a subclass of UIButton:
>>
>> UIColor *baseColor = self.backgroundColor; CGColorRef cgColor =
>> baseColor.CGColor; int32_t model =
>> CGColorSpaceGetModel(CGColorGetColorSpace(cgColor)); const CGFloat
>> *colorComponents = CGColorGetComponents(cgColor); float red = 0.0;
>> float green = 0.0; float blue = 0.0; float alpha = 0.0; if (model ==
>> kCGColorSpaceModelRGB) { red = colorComponents[0]; green =
>> colorComponents[1]; blue = colorComponents[2]; alpha =
>> colorComponents[3]; }
>>
>> It doesn't matter which background color I choose for the button in
>> Interface Builder, all the main 3 color components are always 1. Yes,
>> I double-checked that I had a valid reference to my button, I just
>> don't get it.
>>
>> Anybody sees what I'm doing wrong?
>>
>> -Laurent.
>
> (Sent this off-list by accident.)
>
> Since nothing jumped out at me as obviously broken, I implemented your
> code (via direct copy and paste, with just a reference change to run it
> within the controller code) and as I would have expected, it worked fine.
>
> You can find a zipped up copy of the test project at
> http://dl.dropbox.com/u/5847625/QuartzTest.zip
>
> Hopefully looking through it might give you some ideas as to what you
> are doing differently. Use is simple - tap the button, watch the Xcode
> log for output.
>
> The first thing I would check is that your code is not getting run
> before the nib has been fully unpacked and the objects initialized.
> Where/when is your code being run?
>
> Another possibility is that you ran your app with the button in its
> default (white) state, then changed the color in IB but did not clear
> the app from the device or simulator. Sometimes, for reasons that I
> don't understand, you need to fully delete the app before installing it
> lest you end up with stale nibs or other bundle resources.
Sorry, I think I found my problem. There was an initialization call that was defaulting to set the background color of the button to clear color. Oops!
Thanks, Conrad!
-Laurent.
--
Laurent Daudelin
AIM/iChat/Skype:LaurentDaudelin http://www.nemesys-soft.com/
Logiciels Nemesys Software email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden