setRadiusCorner 位于视图底部

发布于 2024-12-21 02:01:19 字数 228 浏览 2 评论 0原文

我有一个带有圆角的视图。 我想让它在视图的两个底角处变圆。 我怎样才能做到这一点?

这是我为视图制作圆角的代码:

CALayer *myLayer = moreInfoView.layer;
[myLayer setCornerRadius:20.0];
[view.layer setMasksToBounds:YES];

可能吗?

谢谢!

i have a view with rounded corners.
I want to make it rounded just at the two bottom corners of the view.
How can i do that?

This is my code that makes the rounded corners for the view:

CALayer *myLayer = moreInfoView.layer;
[myLayer setCornerRadius:20.0];
[view.layer setMasksToBounds:YES];

Is it possible?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

许你一世情深 2024-12-28 02:01:19

仅圆化 UIRectCornerBottomLeftUIRectCornerBottomRight 角:

UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:yourView.bounds
                                           byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight)
                                                 cornerRadii:CGSizeMake(5.0, 5.0)];

CAShapeLayer *layer = [CAShapeLayer layer];
layer.frame = yourView.bounds;
layer.path = path.CGPath;
yourView.layer.mask = layer;

Round only the UIRectCornerBottomLeft and UIRectCornerBottomRight corners:

UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:yourView.bounds
                                           byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight)
                                                 cornerRadii:CGSizeMake(5.0, 5.0)];

CAShapeLayer *layer = [CAShapeLayer layer];
layer.frame = yourView.bounds;
layer.path = path.CGPath;
yourView.layer.mask = layer;
小鸟爱天空丶 2024-12-28 02:01:19

不要认为您可以轻松地使用 CALayer 做到这一点 - 您可以继承 NSView 并创建一个简单的重绘例程。可能最容易使用 http://www.cocoadev.com/index.pl?RoundedRectangles 作为起点(在删除您不想舍入的两个贝塞尔路径之后),然后执行一个简单的操作:

- (void)drawRect:(CGRect)rect
{
    self.layer.masksToBounds = NO;
    self.layer.shadowColor = [[UIColor xxxx] CGColor];
    self.layer.shadowOffset = CGSizeMake(0,2);
    self.layer.shadowRadius = ...
    self.layer.shadowOpacity = ...

    UIBezierPath *path = [UIBezierPath bezierPathWithPartiallyRoundedRect:rect
           byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(20, 20)];
    [[UIColor blackColor] setFill or Stroke];

    [path stroke or fill];
}

在上面的链接中 - 第二个简化的示例使您的生活更轻松 - 因为您可以简单地使其中两个“路径”线到点:..'。

Don't think you can do that with the CALayer with ease - you could subclass NSView and make a simple redraw routine. May be easiest to use http://www.cocoadev.com/index.pl?RoundedRectangles as a starting point (after removing the two bezier Paths you do not want to have rounded) and then do a simple:

- (void)drawRect:(CGRect)rect
{
    self.layer.masksToBounds = NO;
    self.layer.shadowColor = [[UIColor xxxx] CGColor];
    self.layer.shadowOffset = CGSizeMake(0,2);
    self.layer.shadowRadius = ...
    self.layer.shadowOpacity = ...

    UIBezierPath *path = [UIBezierPath bezierPathWithPartiallyRoundedRect:rect
           byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(20, 20)];
    [[UIColor blackColor] setFill or Stroke];

    [path stroke or fill];
}

In above link - the second simplified example makes your live easier - as you can simply make two of them 'path lineToPoint: ..'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文