UIView上的圆角

9
我对如何实现圆角感到困惑,我看了大约10篇其他文章,但没有一篇对我有用。我做得对吗?
#import "QuartzCore/QuartzCore.h" // in my ViewController.h

- (void)viewDidLoad
{
[super viewDidLoad];

     self.backgroundLayer.cornerRadius = 10.0f;
}

如果有人能在这方面帮助我,那将不胜感激。

1
什么其他的十篇文章?因为如果他们是这样做的,那么对于你所要求的内容,他们是错误的,不应该被接受为答案。此外,我不相信有任何叫做 self.backgroundLayer 的东西,你想要的是 self.view.layer.cornerRadius - Popeye
2个回答

12

尝试打开masksToBounds。此外,backgroundLayer是什么?

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.layer.cornerRadius = 10.0f;
    self.view.layer.masksToBounds = YES;
}

10

是的,你是正确的,但设置 self.backgroundLayer.layer.borderWidth,我放下面的代码可能对你有帮助。

UIView 添加圆形边框

添加 #import "QuartzCore/QuartzCore.h" 框架。(你已经做过了

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];

在你的情况下给 UIView边框


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接