OGeek|极客世界-中国程序员成长平台

标题: ios - 如何使用 uibezierpath 绘制 uiview 的底部曲线? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 05:39
标题: ios - 如何使用 uibezierpath 绘制 uiview 的底部曲线?

我尝试使用 uibezierpath 在 UIimageview 上绘制底部曲线。我不知道该怎么做?

    - (void)setMaskToUIView*)view byRoundingCorners: 
   (UIRectCorner)corners
   {
      UIBezierPath *rounded = [UIBezierPath 
      bezierPathWithRoundedRect:view.bounds

      byRoundingCorners:corners

      cornerRadii:CGSizeMake(200.0, 200.0)];
      CAShapeLayer *shape = [[CAShapeLayer alloc] init];
      [shape setPath:rounded.CGPath];
      view.layer.mask = shape;
    }

我已经尝试过这样的 https://imgur.com/a/WKykdyU

我期望 https://imgur.com/a/BqETMlc 的输出



Best Answer-推荐答案


这应该可以帮助你开始......

enter image description here

使用 UIBezierPath:

这是一个简单的 UIView 子类:

@implementation BottomCurveView

- (void)layoutSubviews {
    [super layoutSubviews];

    CGRect rect = self.bounds;
    CGFloat y = rect.size.height - 80.0;
    CGFloat curveTo = rect.size.height;

    UIBezierPath *myBez = [UIBezierPath new];
    [myBez moveToPoint:CGPointMake(0.0, y)];
    [myBez addQuadCurveToPoint:CGPointMake(rect.size.width, y) controlPoint:CGPointMake(rect.size.width / 2.0, curveTo)];
    [myBez addLineToPoint:CGPointMake(rect.size.width, 0.0)];
    [myBez addLineToPoint:CGPointMake(0.0, 0.0)];
    [myBez closePath];

    CAShapeLayer *maskForPath = [CAShapeLayer new];
    maskForPath.path = myBez.CGPath;
    [self.layer setMask:maskForPath];
}

@end

这会生成上面 200 磅高的图像。

关于ios - 如何使用 uibezierpath 绘制 uiview 的底部曲线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57788503/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4