Skip to content

Instantly share code, notes, and snippets.

@uchicago
Created October 5, 2011 15:53
Show Gist options
  • Save uchicago/1264798 to your computer and use it in GitHub Desktop.
Save uchicago/1264798 to your computer and use it in GitHub Desktop.
Create a simple rounded rectangle UIButton programmatically.
// Create a standard UIButton programmatically using convenience method
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// Set the location (x,y) and size (width,height) of the button
button.frame = CGRectMake(100,100,300,50);
// Add a button title
[button setTitle:@"My Button" forState:UIControlStateNormal];
// Create the target-action for the touch event
[button addTarget:self
action:@selector(buttonTouched:)
forControlEvents:UIControlEventTouchUpInside];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment