Skip to content

Instantly share code, notes, and snippets.

@alvareztech
Last active January 4, 2016 18:08
Show Gist options
  • Save alvareztech/8658210 to your computer and use it in GitHub Desktop.
Save alvareztech/8658210 to your computer and use it in GitHub Desktop.
iOS: Add UIButton programmatically.
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[myButton setTitle:@"My Text" forState:UIControlStateNormal];
[myButton addTarget:self action:@selector(aMethod:) forControlEvents:UIControlEventTouchDown];
myButton.frame = CGRectMake(10, 10, 100, 44);
[self.view addSubview:myButton];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment