gpt4 book ai didi

ios - 为圆角的UIImage添加边框

转载 作者:行者123 更新时间:2023-12-01 18:14:30 24 4
gpt4 key购买 nike

我有一个矩形的UIImage,我想使它变圆并带有边框,我在SO上发现了一个使它变圆并起作用的问题,这是代码:

- (UIImage*) roundCorneredImage: (UIImage*) orig radius:(CGFloat) r {
UIGraphicsBeginImageContextWithOptions(orig.size, NO, 0);
[[UIBezierPath bezierPathWithRoundedRect:(CGRect){CGPointZero, orig.size}
cornerRadius:r] addClip];
[orig drawInRect:(CGRect){CGPointZero, orig.size}];
UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}

但是知道我在尝试如何在图像周围形成白色边框,但没有结果,我该怎么办?

最佳答案

尝试这个 :

- (UIImage*) roundCorneredImage: (UIImage*) orig radius:(CGFloat) r {
UIGraphicsBeginImageContextWithOptions(orig.size, NO, 0);
UIBezierPath *bezierPath =[UIBezierPath bezierPathWithRoundedRect:(CGRect){CGPointZero, orig.size}
cornerRadius:r];
[bezierPath setLineWidth:6.0];
[[UIColor whiteColor] setStroke];
[bezierPath stroke];
[bezierPath addClip];

[orig drawInRect:(CGRect){CGPointZero, orig.size}];
UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}

关于ios - 为圆角的UIImage添加边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23810435/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com