• 图片裁剪成圆形(无边框)


    /**

     *  图片裁剪成圆形(无边框)

     */

    - (UIImage *)imageWithCornerRadius:(CGFloat)radius {

        

        CGFloat sideLength = MAX(self.size.width, self.size.height);

        CGRect rect = (CGRect){0.f, 0.f, sideLength, sideLength};

        

        UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0.0);

        CGContextAddPath(UIGraphicsGetCurrentContext(),

                         [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:sideLength * 0.5].CGPath);

        CGContextClip(UIGraphicsGetCurrentContext());

        

        CGFloat imgX = (sideLength - self.size.width) * 0.5;

        CGFloat imgY = (sideLength - self.size.height) * 0.5;

        CGRect imgRect = (CGRect){imgX, imgY, self.size};

        

        [self drawInRect:imgRect];

        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

        

        UIGraphicsEndImageContext();

        return image;

    }

  • 相关阅读:
    request
    href="#"
    可展开收起的客服导航。
    JS添加父节点的方法。
    精简漂亮的导航浮动菜单显示特效演示
    竖排导航
    仿新浪微博
    鼠标滑过改变文字
    滚动函数
    一些常用的兼容函数。
  • 原文地址:https://www.cnblogs.com/chenzq12/p/6213715.html
Copyright © 2020-2023  润新知