Search code examples
iosios6uibutton

Add a button to my default view in iOS 6


I have the following code (just started learning ios):

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect frame = CGRectMake(0.0, 0.0, 300, 600);
button.frame = frame;   

How do I get it to show up on my view? And to add a title?


Solution

  • Try this Write this code in the ViewDidLoad method .

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button setTitle:@"Show View" forState:UIControlStateNormal];
    button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
    [self.view addSubview:button];