• 第三篇、image 设置圆角的几种方式


    第一种:

    就拿view来举例
    view.layer.masksToBounds=YES; //设置为yes,就可以使用圆角
    view.layer.cornerRadius= 5; //设置它的圆角大小
    view.layer.borderWidth=1; //视图的边框宽度
    view.layer.borderdg= [[UIdggray  dg].CGdg]; //视图的边框颜色

    第二种:

    //初始化CAShapeLayer
        CAShapeLayer *shapeLayer = [CAShapeLayer layer];
        //设置shapeLayer路径和圆角弧度
        shapeLayer.path = [UIBezierPath bezierPathWithRoundedRect:
                           self.imageView.bounds cornerRadius:40].CGPath;
        //设置ImageView的蒙版
        self.imageView.layer.mask = shapeLayer;

    第三种:

    -(UIImage *)getImageRadius:(CGFloat)radius andImage:(UIImage *)image{
    
        CGFloat scale = [UIScreen mainScreen].scale;
        UIGraphicsBeginImageContextWithOptions(image.size, NO, scale);
        CGContextRef c = UIGraphicsGetCurrentContext();
        CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
        UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:radius];
        CGContextAddPath(c, path.CGPath);
        CGContextClip(c);
        [image drawInRect:rect];
        CGContextDrawPath(c, kCGPathFillStroke);
        UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return img;
    }
  • 相关阅读:
    南邮OJA题
    Executors工厂类创建线程池的底层实现
    Linux kernel 中的per_cpu宏
    [置顶] 高并发服务器的设计内存池的设计
    数据列表DataList模板之实例
    软件开发无敌心得篇
    嵌入式学习笔记之UART通信协议
    正则表达式 进阶(二)
    11687 Digits
    DELPHI接口转化为COM接口
  • 原文地址:https://www.cnblogs.com/HJQ2016/p/5978667.html
Copyright © 2020-2023  润新知