Re: Missing something with CGColorGetComponents()
Re: Missing something with CGColorGetComponents()
- Subject: Re: Missing something with CGColorGetComponents()
- From: Conrad Shultz <email@hidden>
- Date: Thu, 14 Oct 2010 12:32:53 -0700
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
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.
- --
Conrad Shultz
Synthetiq Solutions
www.synthetiqsolutions.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.14 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAky3WuUACgkQaOlrz5+0JdVEiACdG+swLaEbN7C6Z3GFb0DxDwQe
jXAAnA/dj9SotvR9vwdF3DSeNxoQEr67
=If9M
-----END PGP SIGNATURE-----
_______________________________________________
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