zoukankan      html  css  js  c++  java
  • 设置圆角图片

    开发中常常会需要将图片设置成圆角,下面就介绍3种实现方法:

    圆角图片

    第一种方法:通过设置layer的属性,实现圆角(这种方法在iOS9以前可能会造成卡顿现象,但iOS9以后就不会再出现这样的问题)

    imageView.layer.cornerRadius = imageView.frame.size.width * 0.5;   // 设置圆角半径
    imageView.layer.masksToBounds = YES;     // 超出主层边框就要裁剪掉
    

    第二种方法:runtime实现圆角(这里其实就是利用runtime实现的)

    runtime实现圆角

    第三种方法:通过画图实现圆角

            // 1.开启图形上下文
              UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);
            // 2.描述裁剪区域
            UIBezierPath *clipPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
            
            // 3.设置裁剪区域
            [clipPath addClip];
            
            // 4.画图片
            [image drawAtPoint:CGPointZero];
            
            // 5.从上下文取出图片
            image = UIGraphicsGetImageFromCurrentImageContext();
            imageView.image = image;
            
            // 6.关闭上下文
            UIGraphicsEndImageContext();
    
  • 相关阅读:
    2021.3.3
    2021.3.2
    2021.3.1
    2021.2.28(每周总结)
    2021.2.27
    2021.2.26
    2021.2.25
    2021.2.23
    Redis系统学习之五大基本数据类型(List(列表))
    Redis系统学习之五大基本数据类型(String(字符串))
  • 原文地址:https://www.cnblogs.com/zhenzhen123/p/5280659.html
Copyright © 2011-2022 走看看