zoukankan      html  css  js  c++  java
  • iOS使用UIBezierPath画圆角

    第一种方法:通过设置layer的属性

    这种方法简单,但是很影响性能,特别是在UIcollectionView中展示大量圆角图片,一般在正常的开发中使用很少

    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
    //设置圆角
    imageView.layer.cornerRadius = imageView.frame.size.width / 2;
    //将多余的部分切掉
    imageView.layer.masksToBounds = YES;
    [self.view addSubview:imageView];
    

     第二方法:使用CAShapeLayer和UIBezierPath设置圆角,种最好,对内存的消耗最少,而且渲染快速

        UIImageView *view = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
        view.backgroundColor = [UIColor redColor];
        [self.view addSubview:view];
        
        UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectEdgeLeft | 
    UIRectCornerBottomLeft cornerRadii:CGSizeMake(10, 10)]; CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init]; maskLayer.frame = view.bounds; maskLayer.path = path.CGPath; view.layer.mask = maskLayer;

     UIRectEdgeLeft 可以根据需求设置需要设置圆角的位置。

  • 相关阅读:
    zoj 3233 容斥原理 + 双条件
    bzoj 1038 瞭望塔 半平面交 + 最小值 枚举
    linux 常用命令
    Vue路由
    luffycity项目开发
    Vue组件化开发
    Vue对象提供的属性功能
    Vue快速入门
    Django-DRF(路由与扩展功能)
    Django-DRF(视图相关)
  • 原文地址:https://www.cnblogs.com/Crazy-ZY/p/6226010.html
Copyright © 2011-2022 走看看