2

An attempt to programmatically create a rounded rectangular button in an Objective-C View Controller in Xcode 6 and iOS 8.1 only produces a non-rounded rect button. The UIButton buttonWithType: method is being used.

Why?

//
//  ViewController.m
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)loadView // Called the first time the view property is accessed.
{
    CGRect viewRect = [[UIScreen mainScreen] bounds];
    UIView *view = [[UIView alloc] initWithFrame:viewRect];
    self.view = view;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Set the view's background color.
    self.view.backgroundColor = [UIColor colorWithRed:0.462 green:0.999 blue:0.999 alpha:1.0];

    // Create a button.
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    // Place and size the button on the screen.
    btn.frame = CGRectMake(100, 100, 90, 44);
    // Set the button's background color.
    btn.backgroundColor = [UIColor yellowColor];
    // Set the button's normal title.
    [btn setTitle:@"Test Button" forState:UIControlStateNormal];
    // Add the button as a subview.
    [self.view addSubview:btn];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
  • 1
    First you should have searched SO before posting question, anyhow check this link out http://stackoverflow.com/a/19143035/2458651 – zaheer Dec 25 '14 at 04:00
  • Zaheer, neither your comment nor link was helpful. I did search SO prior to posting my question. Thank you for nothing. – Mario Abruzzi Dec 25 '14 at 04:33
  • Dear Mario Abruzzi, the very first line in the answer was buyButton.layer.cornerRadius = 2; – zaheer Dec 25 '14 at 05:40

1 Answers1

1

Add this line and try:

btn.layer.cornerRadius = 5;
Zigii Wong
  • 7,766
  • 8
  • 51
  • 79