UIView Access Subviews


 

UIView Access Subviews

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

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

Ads