Draw labels and buttons programmatically onto a View
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, labe开发者_Go百科ls and pictures dynamically? Has somebody an example?
Read
- Create UIButton Programmatically
- Creating programmatically a label (UILabel)
And Create then in the View. Here is a very good tutorial on how to do that !
Good Luck !
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.
精彩评论