views:

67

answers:

2

I want to overlay an image over a button. the button has a background image. If i want to overlay a semi transparent image over the button, suppose i overlay a red color image, which is semi transparent. Can any one suggest how to do that? Suggest some documentation.

+2  A: 
UIImageView *overlay = [[UIImageView alloc] initWithImage:...];
[overlay setAlpha:0.5];

UIButton *button = [[UIButton alloc] initWithType:UIButtonTypeRoundedRect];
[button setBackgroundImage:...];

[button addSubview:overlay];
[overlay release];

UIButton also has an image property as well as a backgroundImage property, although I'm unsure how transparency would work with it.

http://developer.apple.com/iphone/library/documentation/uikit/reference/UIButton_Class/UIButton/UIButton.html

dc
+1  A: 

Following dc answer, note that changing the button alpha will affect also the overlay transparency, so check that button alpha is 1.0f (default value).

Note also that you should release the overlay variable after adding it as subview to button, otherwise, you'll get a memory leak.

Meir Assayag
Thanks, forgot about that.
dc