Skip to content

Instantly share code, notes, and snippets.

@TheCodeEngine
Last active October 10, 2015 23:28
Show Gist options
  • Save TheCodeEngine/3767376 to your computer and use it in GitHub Desktop.
Save TheCodeEngine/3767376 to your computer and use it in GitHub Desktop.
UIButton programmatically
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(20, 20, 200, 44); // position in the parent view and set the size of the button
[myButton setTitle:@"Click Me!" forState:UIControlStateNormal];
// add targets and actions
[myButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
// add to a view
[self.view addSubview:myButton];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment