Most colors you will set in Interface Builder rather than in Xcode on the beginning, but if you need to change it dynamically, I’m sorry you need to know it.
I will present you the way how to change the background color of UIImageView – in other words image, using UIColor. By image I mean simply placeholder for image, because UIImageView can be just a colored rectangle without any PNG/JPG at all. But UIColor is very flexible, using the same code, you can change not only background colors, but shadow shadowColor (for UILabel), textColor (also UILabel) and I’m sure there is even more properties I can’t remember in this particular moment.
The code is very simple (as usuall):
myImage.backgroundColor = [UIColor blueColor];
Above code will cause, that myImage’s frame will be blue.
You can experiment with a lot of colors like:
- blackColor
- brownColor
- cyanColor
- grayColor
- greenColor
- …
While in Xcode write “[UIColor " and press escape to a list of all possible ending and you will get a lot of standard colors you can use.
If you would like to make your image (or anything else) transparent in some percent you can use alpha property:
myImage.alpha = 0.5;
This will make your image half transparent.
RGB
Of course it's not all. iPhone / iPod touch are devices able to display millions of colors (so they said). I have never counted them but it's very easy to display any color giving the amount of red, green and blue... and alpha at once.
The code is also a single line:
image.backgroundColor = [UIColor colorWithRed:121/255 green:42/255 blue:120/255 alpha:0.9];
Predefined textures
Depending of brightness of your screen viewFlipsideBackgroundColor looks like some kind of black material. I guess every iPhone user is familiar with the second one, it's the same background as grouped UITableView uses (see Settings application). You can use them like they were a normal color.
myImage.backgroundColor = [UIColor viewFlipsideBackgroundColor]; myImage.backgroundColor = [UIColor groupTableViewBackgroundColor];
One more thing
There is an interesting color clearColor. What does it to? Well maybe it wan't be important right now, as long as you can change any object's property alpha to zero. But clearColor will simply erase any color, very helpful in 2D graphics (Quartz).
Another one more thing
As usuall I prepared for you a project. An application where you can test any color you need changing the RGB and alpha using sliders and the preview of viewFlipsideBackgroundColor and groupTableViewBackgroundColor.



look videos watch
Thanks for the publish. My spouse and i have always observed that a lot of people are desperate to lose weight when they wish to appear slim in addition to looking attractive. Nevertheless, they do not usually realize that there are more benefits for losing weight as well. Doctors claim that overweight people suffer from a variety of illnesses that can be directly attributed to their excess weight. The great news is that people who definitely are overweight and also suffering from diverse diseases can help to eliminate the severity of their own illnesses simply by losing weight. It is possible to see a gradual but noticeable improvement with health as soon as even a moderate amount of fat reduction is accomplished gywl512.
Need to subscribe to this blog
Hi Chris,
I am set to speak on printing at the iAMDA ( http://iamda.org/ ) conference in NY this weekend. I’ve been trying to find the “color space” for the iPhone/iPad. Do you know what it is and what is the conversion like to Adobe RGB or ProPhoto? Is there an easy explanation for UI color? I’m trying to get artists who create work on mobile devices to print out their work with great results.
Thank you for any info
I am in an iPod/iPad dev class and we are learning from the beginning. This stuff is fairly new to us. My group built a calculator and now we are trying to utilize color changing in it also. We are running into problems with the RGB sliders. They aren’t changing the image box with the colors. My group tried to compile your project and step through it but we get an SDK error. Is it a possibility to show a picture of your relationship screen?
Thanks~Ted
Who was it that once said, “Reason is immortal all else mortal..”.