美文网首页
iOS-设置圆角的方法

iOS-设置圆角的方法

作者: SK丿希望 | 来源:发表于2019-02-23 11:04 被阅读0次

1.通过设置layer的属性

view.layer.cornerRadius = ??;
view.layer.masksToBounds = YES;

2.使用贝塞尔曲线UIBezierPath和Core Graphics框架画出一个圆角

    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(15, 100, 60, 60)];
    imageView.image = [UIImage imageNamed:@"我的头部BG"];
    // 开启图形上下文
    UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, 1.0);
    
    //使用贝塞尔曲线画出一个圆形图
    [[UIBezierPath bezierPathWithRoundedRect:imageView.bounds cornerRadius:imageView.frame.size.width] addClip];
    [imageView drawRect:imageView.bounds];
    // 从图形上下文中获取圆角图片
    imageView.image = UIGraphicsGetImageFromCurrentImageContext();
    //关闭图形上下文
    UIGraphicsEndImageContext();
    [self.view addSubview:imageView];

3.使用CAShapeLayer和UIBezierPath设置圆角

    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(15, 100, 60, 60)];
    imageView.image = [UIImage imageNamed:@"我的头部BG"];
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:imageView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomRight cornerRadii:imageView.bounds.size];
    
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
    //设置大小
    
    maskLayer.frame = imageView.bounds;
    //设置形状
    maskLayer.path = maskPath.CGPath;
    imageView.layer.mask = maskLayer;
    [self.view addSubview:imageView];

相关文章

  • iOS-设置圆角的方法

    1.通过设置layer的属性 2.使用贝塞尔曲线UIBezierPath和Core Graphics框架画出一个圆...

  • iOS设置圆角的四种方法

    原文iOS设置圆角的四种方法iOS设置圆角的方法及指定圆角的位置 一、设置CALayer的cornerRadius...

  • UITableViewCell 上控件设置圆角

    自定义UITableViewCell 上面的控件设置圆角 自定义cell的drawRect 方法,并在该方法里面设置圆角

  • iOS设置圆角的四种方法(附性能评测)

    四种设置圆角的方法 从网上收集了各种设置圆角的方法,总结起来有以下四种: 设置 layer 的 cornerRad...

  • iOS设置圆角的方法及指定圆角的位置

    在iOS开发中,我们经常会遇到设置圆角的问题, 以下是几种设置圆角的方法: 第一种方法: 通过设置layer的属性...

  • UIImageView圆角设置总结

    在iOS开发中,我们经常会遇到设置圆角的问题, 以下是几种设置圆角的方法: 第一种方法: 通过设置layer的属性...

  • iOS-高效设置圆角

    一、前因 CALayer由背景色backgroundColor、内容contents、边缘borderWidth&...

  • iOS-设置图片圆角

    常用设置: 适用 xib 或者 storyboard 绘图做法 使用图层过量会有卡顿现象, 特别是弄圆角或者阴影会...

  • 给View加任意圆角

    我们经常用到的设置圆角的方法 但是这样,如果遇到控件的高度小于想要设置的圆角的一半,择圆角最多只能设置成控件高度的...

  • 设置圆角方法

    首先你是否是这么设置的: // cornerRadius 设置为self.iconImage图片宽度的一半(圆形图...

网友评论

      本文标题:iOS-设置圆角的方法

      本文链接:https://www.haomeiwen.com/subject/rpgugxtx.html