Here is a sample code to add a UIButton Programmatically in iOS using Objective-C:
Code:
UIButton *button_name=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
[button_name setTitle:@"ButtonName" forState:UIControlStateNormal];
[button_name setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
button_name.backgroundColor=[UIColor clearColor];
[[button_name layer] setBorderWidth:1.0f];
[[button_name layer] setBorderColor:[UIColor greenColor].CGColor];
[button_name addTarget:self action:@selector(save) forControlEvents: UIControlEventTouchDown ];
[self.view addSubview: button_name];
To make Rounded-Rect button use the following code:
UIButton *button_name = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button_name.frame = CGRectMake(50, 200, 200, 40);

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.