Home Tutorial Iphone Examples Creating UIView Programmatically

 
 

Share on Google+Share on Google+
Creating UIView Programmatically
Posted on: April 14, 2010 at 12:00 AM
Advertisement
The example will show you how to create a UIView programmatically.
Creating UIView Programmatically

The example will show you how to create a UIView programmatically.

In the previous example, we have illustrated you how to load the next UIView using pushViewControler. This example is also similar to it.. the only difference is that prior, we were loading the UIView that already have been added in the application. But here we are going to create a UIView programmatically.

Code to create UIView Programmatically

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{
//creating a new UIViewController
UIViewController *newViewController = [[UIViewController alloc] init];
newViewController.title = @"New UIView";
viewOneViewController.view.backgroundColor = [UIColor greenColor];
//Pushing new view to load
[self.navigationController pushViewController:newViewController animated:YES];

}

In the code, you can see that we are creating a new view using UIViewController and allocated it memory using

UIViewController *newViewController = [[UIViewController alloc] init];

"newViewController" is the name of our UIView that we have just created.

You can also set Title and Background color of UIView Programmatically such as...
//Setting Title for new UIViewController
newViewController.title = @"New UIView";

//Setting background color for new UIViewController
viewOneViewController.view.backgroundColor = [UIColor greenColor];

Download Code

Advertisement

Related Tags for Creating UIView Programmatically:


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.

Posted on: April 14, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com