Quantcast
Channel: Developer Feed - Snippet
Viewing all articles
Browse latest Browse all 178

How to create a UIButton programatically in iOS?

$
0
0
  1. UIButton *button =[UIButton buttonWithType:UIButtonTypeRoundedRect];
  2.  
  3. button.frame= CGRectMake(100.0, 200.0, 180.0, 60.0);
  4.  
  5. // on click, which method to call
  6. [button addTarget:self      action:@selector(onClickMethodToCall:) forControlEvents:UIControlEventTouchDown];
  7.  
  8. // title of button
  9. [button setTitle:@"Click Me" forState:UIControlStateNormal];
  10.  
  11. // if has to have a image
  12. UIImage *image =[UIImage imageNamed:@"image.png"];
  13. [image setImage:img forState:UIControlStateNormal];
  14.  
  15. // finally add
  16. [view addSubview:button];

Viewing all articles
Browse latest Browse all 178

Trending Articles