zoukankan      html  css  js  c++  java
  • 设置图片圆角的三种方式

        //了解切圆角的方式有三种,我们一种一种来看
        //圆角的第一种方式:(设置Layer属性)
        UIImageView *imageView = [[UIImageView alloc]init];
        imageView.backgroundColor = [UIColor purpleColor];
        imageView.frame = CGRectMake(110, 100, 200, 200);
        imageView.image = [UIImage imageNamed:@"1"];
        //将多余的部分切掉
        imageView.layer.masksToBounds = YES;
        //设置圆角
        imageView.layer.cornerRadius = imageView.frame.size.width / 2;
        [self.view addSubview:imageView];
        //圆角的第二种方式:(使用贝塞尔曲线:UIBezierPath和Core Graphics 框架画出一个圆角)
        UIImageView *imageView = [[UIImageView alloc]init];
        imageView.backgroundColor = [UIColor purpleColor];
        imageView.frame = CGRectMake(110, 100, 200, 200);
        imageView.image = [UIImage imageNamed:@"1"];
        /**
         *  对图片进行画图
         *
         *  @param size#>   图片的大小 description#>
         *  @param opaque#> 是否透明 description#>
         *  @param scale#>  比例大小 description#>
         *
         *  @return nil
         */
        UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, 1.0);
        
        /**
         *  使用贝塞尔曲线画出一个圆形图
         *
         *  @param CGRect 图片路径
         *
         *  @return 圆角大小
         */
        [[UIBezierPath bezierPathWithRoundedRect:imageView.bounds cornerRadius:imageView.frame.size.width] addClip];
        
        [imageView drawRect:imageView.bounds];
        
        imageView.image = UIGraphicsGetImageFromCurrentImageContext();
        
    //    结束画图
        UIGraphicsEndImageContext();
        
        [self.view addSubview:imageView];
    // 圆角的第三种方式:(使用CAShapeLayer和UIBezierPath)设置圆角 注:此方法消耗的内存少,渲染快.
    // 首先导入框架 #import <AVFoundation/AVFoundation.h>
        UIImageView *imageView = [[UIImageView alloc]init];
            imageView.backgroundColor = [UIColor purpleColor];
            imageView.frame = CGRectMake(110, 100, 200, 200);
            imageView.image = [UIImage imageNamed:@"1"];
        UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:imageView.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:imageView.bounds.size];
        
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
        //设置大小
        maskLayer.frame = imageView.bounds;
        //设置图形样子
        maskLayer.path = path.CGPath;
        imageView.layer.mask = maskLayer;
        
        [self.view addSubview:imageView];
  • 相关阅读:
    关于ArcMap中的地图文档单位
    洛谷—— P2983 [USACO10FEB]购买巧克力Chocolate Buying
    COGS——T 826. [Tyvj Feb11] GF打dota
    洛谷—— P1855 榨取kkksc03
    洛谷—— P2663 越越的组队
    COGS——T 1578. 次小生成树初级练习题
    Django中间件
    March 7 2017 Week 10 Tuesday
    March 6 2017 Week 10 Monday
    March 5 2017 Week 10 Sunday
  • 原文地址:https://www.cnblogs.com/LzwBlog/p/5667033.html
Copyright © 2011-2022 走看看