ImageTransparency In iPhone

In this application we will see how to image visible using change slider value. So let see how it will be work.

Step 1: Create a View base application using template. Give the application name “ImageTransparency”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Xpand classes and notice Interface Builder created the ImageTransparencyViewController class for you. Expand Resources and notice the template generated a separate nib, ImageTransparencyViewController.xib, for the “ImageTransparency”.

Step 4: In the ImageTransparencyViewController.h file,we have added UIImageView for displaying imageview, UISlider and added one method. So make the following changes in the file.


#import <uikit/UIKit.h>

@interface ImageTransparencyViewController : UIViewController {

IBOutlet UIImageView*image;
IBOutlet UISlider*sliderValue;


@property(nonatomic,retain) IBOutlet UIImageView*image;
@property(nonatomic,retain) IBOutlet UISlider*sliderValue;




Step 5:Double click the ImageTransparencyViewController.xib file and open it to the Interface Builder. Double click in the view icon and open it in the view window. Select the view window and bring up Attribute Inspector and change the background color. Now drag Slider from the library and place it to the view window, and drag File’s Owner icon to the View icon and select sliderValue. Select the slider and bring up Connection Inspector and connect ValueChanged to the File’s Owner icon and select changeslidervalue: method. Another time drag the ImageView from the library and place it to the view window, select the imageview from the view window and bring up Attribute Inspector and change the alpha value into 0.00 (See figure below). Connect File’s Owner icon to the imageview and select image. Drag the label from the library and place it to the view window and change the label name into “Move Slider:”. We have done all the connection, now save the  ImageTransparencyViewController.xib file, close it, and go back to the Xcode.

Step 6: Open the ImageTransparencyViewController.m file and make the following changes in the file:


-(IBAction) changeslidervalue:(id)sender {
image.alpha = sliderValue.value;



Step 7: Now compile and run the application in the Simulator.

You can Download sourceCode from here ImageTransparency 2

Leave a Comment:

Patrick says June 8, 2010

Thanks, very helpful.

I did the above, but without the @property and it still worked fine. Without the setter for the image, how did the image.alpha get set?

Sushant says June 8, 2010

We have initialized the alpha value and Slider value into 0.00, in the Interface Builder , and set image.alpha = sliderValue.value; that means when we increase the slider value, alpha value also change automatically.

Ryan says January 11, 2011

Great tutorial Sushant,
I have done this, but I want to apply this to 4 buttons, so the user can hide/show them. Is this easy from here?

Thanks for any response….

Add Your Reply