Skip to content

Instantly share code, notes, and snippets.

@MaximAlien
Created December 9, 2015 13:35
Show Gist options
  • Save MaximAlien/f4b5bf7cebc48fe99564 to your computer and use it in GitHub Desktop.
Save MaximAlien/f4b5bf7cebc48fe99564 to your computer and use it in GitHub Desktop.
[iOS] Example code for adding UIButton programatically into the view of the UIViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 22, 200, 100)];
[button setTitle:@"Back" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
[self.view bringSubviewToFront:button];
[self.view setBackgroundColor:[UIColor whiteColor]];
}
- (void)buttonPressed:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment