Share on Google+Share on Google+

UIView Access Subviews

Advertisement
In the example, you'll learn how to create and access a subview on UIView.

UIView Access Subviews

In the example, you'll learn how to create and access a subview on UIView.

Syntax of adding subview at UIView.
- (void)addSubview:(UIView *)view;

Creating and accessing a subview : In the example we are creating & adding a UIImageView on the UIView as a subview programatically. The method can be written into the "viewDidLoad" method that do the additional setup after the loading view.

a simple example:

- (void)viewDidLoad {
[super viewDidLoad];

UIImage *one = [UIImage imageNamed:@"imagename.png"];
UIImage *two = [UIImage imageNamed:@"Krishna_Arjuna.png"];

//Creating a subview
UIImageView *imageView1 = [[[UIImageView alloc] initWithImage:one] autorelease];
UIImageView *imageView2 = [[[UIImageView alloc] initWithImage:two] autorelease];

imageView2.alpha = 0;

//Adding subview
[self.view addSubview:imageView1];
[self.view addSubview:imageView2];

}

Download Code

Advertisements

Advertisement

Posted on: September 22, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.