【问题标题】:Setting Corners in View [duplicate]在视图中设置角落[重复]
【发布时间】:2012-04-04 17:10:42
【问题描述】:

我知道我可以将带有圆角的 UIView 设为

view.layer.cornerRadius = 10;

现在我想知道如何在选定的角上制作圆角?就像在左上角和右上角而不是在左下角和右下角一样。我怎么能做到这些?

提前谢谢...

【问题讨论】:

  • 即使不完全重复,我还是通过这些帖子找到了答案。非常感谢您的发现
  • 重复接近投票/链接具有双重目的 - 它们可以防止重复,但它们也可以帮助提问者(以及使用您使用的术语进行搜索的任何其他人)找到他们可能没有的答案在问问题之前遇到。

标签: iphone quartz-2d


【解决方案1】:

这样的东西只会画出顶角 -

- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];

UIBezierPath* roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(44.5, 12.5, 69, 46) byRoundingCorners: UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii: CGSizeMake(10, 10)];
[[UIColor whiteColor] setFill];
[roundedRectanglePath fill];

[[UIColor blackColor] setStroke];
roundedRectanglePath.lineWidth = 0.5;
[roundedRectanglePath stroke];

}

【讨论】:

    【解决方案2】:

    两种方法:

    1. use CALayer mask, mask out the corner you don't want.
    

    2. use Core Graphic, create a clip path.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-15
      • 1970-01-01
      • 2016-10-16
      • 2020-06-07
      • 2020-10-09
      • 1970-01-01
      相关资源
      最近更新 更多