【发布时间】:2014-08-22 14:00:21
【问题描述】:
如何创建带边框的圆形图片(UIGraphics)?
附:我需要画一幅画。
viewDidLoad中的代码:
NSURL *url2 = [NSURL URLWithString:@"http://images.ak.instagram.com/profiles/profile_55758514_75sq_1399309159.jpg"];
NSData *data2 = [NSData dataWithContentsOfURL:url2];
UIImage *profileImg = [UIImage imageWithData:data2];
UIGraphicsEndImageContext();
// Create image context with the size of the background image.
UIGraphicsBeginImageContext(profileImg.size);
[profileImg drawInRect:CGRectMake(0, 0, profileImg.size.width, profileImg.size.height)];
// Get the newly created image.
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
// Release the context.
UIGraphicsEndImageContext();
// Set the newly created image to the imageView.
self.imageView.image = result;
【问题讨论】:
-
以上代码的输出是什么?
-
最简单的方法是修改imageView而不是image。它当然可以修改图像,但修改 imageView 的 .borderColor、.borderWidth、.cornerRadius 和 .maskToBounds 属性要容易得多...
-
@DavidDoyle 我需要画一幅画。
borderWidth不适合 -
@SpaceInvader,为什么
cornerRadius或borderWidth不适合? ://
标签: ios objective-c uigraphicscontext