iOS UIImage设置圆角
发布日期:2021-11-15 02:12:02 浏览次数:9 分类:技术文章

本文共 874 字,大约阅读时间需要 2 分钟。

新建UIImage分类如下:
@interface UIImage (RoundedRectImage)- (UIImage *)setRoundedCorners:(CGFloat)radius andSize:(CGSize)size;@end
#import "UIImage+RoundedRectImage.h"@implementation UIImage (RoundedRectImage)- (UIImage *)setRoundedCorners:(CGFloat)radius andSize:(CGSize)size{    CGRect rect = CGRectMake(0, 0, size.width, size.height);    UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);    CGContextRef ctx = UIGraphicsGetCurrentContext();    UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(radius, radius)];    CGContextAddPath(ctx,path.CGPath);    CGContextClip(ctx);    [self drawInRect:rect];    CGContextDrawPath(ctx, kCGPathFillStroke);    UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext();    UIGraphicsEndImageContext();    return newImage;}

转载地址:https://blog.csdn.net/qq_28379951/article/details/103628149 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:iOS cell 清空子视图
下一篇:iOS 解析crashlog日志

发表评论

最新留言

表示我来过!
[***.240.166.169]2024年04月16日 06时31分44秒