#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *pictureImageView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//設(shè)置圓角各個(gè)方法在下面列出
}
// 基本方式添加圓角
self.pictureImageView.layer.cornerRadius = 20;
self.pictureImageView.layer.masksToBounds = YES;
//使用UIBezierPath和core graphics畫(huà)一個(gè)圓角
UIGraphicsBeginImageContextWithOptions(self.pictureImageView.bounds.size, YES, 0.0);
[[UIBezierPath bezierPathWithRoundedRect:self.pictureImageView.bounds cornerRadius:20]addClip];
[self.pictureImageView drawRect:self.pictureImageView.bounds];
self.pictureImageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//使用Core Graphics框架畫(huà)出一個(gè)圓
UIGraphicsBeginImageContextWithOptions(self.pictureImageView.bounds.size, YES, 1.0);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGRect rect = CGRectMake(0, 0, self.pictureImageView.bounds.size.width, self.pictureImageView.bounds.size.height);
CGContextAddEllipseInRect(ctx, rect);
CGContextClip(ctx);
[self.pictureImageView.image drawInRect:rect];
UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.pictureImageView.image = newImage;
// 使用CAShapeLayer和UIBezierPath設(shè)置圓角
UIBezierPath * maskPath = [UIBezierPath bezierPathWithRoundedRect:self.pictureImageView.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(20, 20)];
CAShapeLayer * maskLayer = [[CAShapeLayer alloc]init];
maskLayer.frame = self.pictureImageView.bounds;
maskLayer.path = maskPath.CGPath;
self.pictureImageView.layer.mask = maskLayer;
// 制定角為圓角
UIBezierPath * maskPath = [UIBezierPath bezierPathWithRoundedRect:self.pictureImageView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(20, 20)];
CAShapeLayer * maskLayer = [[CAShapeLayer alloc]init];
maskLayer.frame = self.pictureImageView.bounds;
maskLayer.path = maskPath.CGPath;
self.pictureImageView.layer.mask = maskLayer;
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。