需要到您正在創建圖像視圖在文件中添加QuartzCore框架在您的項目,然後#import<QuartzCore/QuartzCore. h>
。
UIImageView *myImageview = [[UIImageView alloc] initWithFrame:CGRectMake(130, 200, 60, 60)];
[myImageview setImage:[UIImage imageNamed:@"image.png"]];
myImageview.clipsToBounds = YES:
[self.view addSubview:myImageview];
[self updateImageViewLayer:myImageview.layer withBorderColor:[UIColor redColor] borderWidth:5.f cornerRadius:(myImageview.bounds.width/2.f)];
- (void)updateImageViewLayer:(CALayer*)layer withBorderColor:(UIColor *)color borderWidth:(CGFloat)width cornerRadius:(CGFloat)radius
{
layer.borderWidth = width;
layer.borderColor = color.CGColor;
layer.cornerRadius = radius/2.f;
layer.masksToBounds = YES;
}
我做了一個函數,重用它用於不同的UIImageView
對象。
的可能重複的[IOS:創建一個UIImage或UIImageView的具有圓角(http://stackoverflow.com/questions/7705879/ios-create-a-uiimage-or-uiimageview-with-rounded-corners) – n00bProgrammer