Skip to content

Instantly share code, notes, and snippets.

@Lancewer
Created January 17, 2018 01:24
Show Gist options
  • Save Lancewer/5499737e56b87214babfe57779fab643 to your computer and use it in GitHub Desktop.
Save Lancewer/5499737e56b87214babfe57779fab643 to your computer and use it in GitHub Desktop.
[AddSubviewToSuperViewCenter] how to add a subview to superview's center #UIView #center #iOS #OC

#This simple snippet shows how to add a subview to superview's center.

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIView *innerView = [[UIView alloc] init];
[innerView setBounds:CGRectMake(0, 0, 50, 50)];
[innerView setCenter:self.view.center];
[self.view addSubview:innerView];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment