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();
    
  • 相关阅读:
    mmap函数实现
    linux交换空间
    日志式文件系统
    Linux内核书籍
    进程状态
    form表单中enctype="multipart/form-data"的作用
    php导入excel表格
    什么是隐藏域
    把生成的excel文件直接提供为下载页效果
    到底什么是实例化
  • 原文地址:https://www.cnblogs.com/zhenzhen123/p/5280659.html
Copyright © 2011-2022 走看看