How to add a simple UIButton in a UIView by coding?


CREATE A BUTTON

UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];

button1.frame = CGRectMake(x, y, width, height);

where x and y are coordinates

width is width of the button,height is height of the button

[button1 setTitle:@”Hello” forState:UIControlStateNormal];

ADD THE BUTTON TO PARENT VIEW

[[self view] addSubview:button1];

Copy from http://iosdeveloperz.com/tag/cgrectmake/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s