【问题标题】:Rounded corners on UIView [duplicate]UIView上的圆角[重复]
【发布时间】:2013-03-24 08:47:36
【问题描述】:

我对如何绕过角落感到困惑,我看过大约 10 个其他帖子,但没有一个对我有帮助。我这样做对吗?

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

- (void)viewDidLoad
{
[super viewDidLoad];

     self.backgroundLayer.cornerRadius = 10.0f;
}

如果有人可以帮助我解决这个问题,我们将不胜感激。

【问题讨论】:

  • 其他十个帖子?因为如果他们这样做,他们就错了你所问的,不应该被接受为答案。另外我不相信有什么叫self.backgroundLayer 你想要self.view.layer.cornerRadius

标签: iphone ios objective-c uiview


【解决方案1】:

尝试开启masksToBounds。还有,什么是backgroundLayer?

- (void)viewDidLoad {
    [super viewDidLoad];

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

【讨论】:

    【解决方案2】:

    是的,您是正确的,但设置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];
    

    在你的情况下,给出UIViewborder

    【讨论】:

    • 效果很好,谢谢!
    猜你喜欢
    • 2011-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-03
    • 2021-01-29
    • 2013-05-15
    • 2011-01-24
    相关资源
    最近更新 更多