开发者

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

  1. Create UIButton Programmatically
  2. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜