Reputation: 1954
I'm building an iPhone app in which I should create a new view based upon some data... so how can I programmatically create a new view with buttons, labels and pictures dynamically? Has somebody an example?
Upvotes: 0
Views: 1196
Reputation: 773
First rightclick on your Xcode project (in ios 5) and select "New file">select cocoa touch>objective c class>subclass of uiview>and name your file name. THen add the following code in the .m file.
// Implement loadView to create a view hierarchy programatically, without using a nib.
-(void)loadView {
UIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
[view setAutoresizingMask:UIViewAutoresizingFlexibleHeig ht|UIViewAutoresizingFlexibleWidth];
[view setBackgroundColor:[UIColor blueColor]];
self.view = view;
[view release];
}
Then create the buttons as described in below posts.
Upvotes: 0
Reputation: 10755
Read
And Create then in the View. Here is a very good tutorial on how to do that !
Good Luck !
Upvotes: 5