9

I am confused on how I would round corners, I've seen about 10 other posts and non of them have helped me. Am I doing this correctly?

#import "QuartzCore/QuartzCore.h" // in my ViewController.h

- (void)viewDidLoad
{
[super viewDidLoad];

     self.backgroundLayer.cornerRadius = 10.0f;
}

If somebody could help me out on this it'd be greatly appreciated.

iPatel
  • 46,010
  • 16
  • 115
  • 137
cthrp
  • 133
  • 1
  • 1
  • 9
  • 1
    What ten other posts? Cause if they did it this way they are wrong for what you have asked and shouldn't be accepted as answers. Also I don't believe there is anything called `self.backgroundLayer` you want `self.view.layer.cornerRadius`. – Popeye Mar 24 '13 at 10:29

2 Answers2

12

Try turning on masksToBounds. Also, what is backgroundLayer?

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.layer.cornerRadius = 10.0f;
    self.view.layer.masksToBounds = YES;
}
Sherman Lo
  • 2,759
  • 20
  • 20
10

Yes, You are correct but set self.backgroundLayer.layer.borderWidth, I put following code might be helpful in your case.

For give round Border Of UIView.

Add #import "QuartzCore/QuartzCore.h" fram work. (you've already done it)

self.backgroundLayer = [UIView alloc] initWithFrame:CGRectMake(@"As You Want")];
self.backgroundLayer.backgroundColor = [UIColor redColor];
self.backgroundLayer.layer.cornerRadius = 10.0; // set cornerRadius as you want.
self.backgroundLayer.layer.borderColor = [UIColor lightGrayColor].CGColor; // set color as you want.
self.backgroundLayer.layer.borderWidth = 1.0; // set borderWidth as you want.
[self.view addSubView:self.backgroundLayer];

in your case give border of UIView.

whitneyland
  • 10,632
  • 9
  • 60
  • 68
iPatel
  • 46,010
  • 16
  • 115
  • 137