4
我有一个40x40的方形图像,我想通过剪裁进行修剪,但也在图像周围放置了黑色的5像素边框。我如何掩盖一个圆形的方形图像,并在图像周围放置黑色边框
我有被遮蔽的正方形图像所以它现在轮
UIImage *image = self.imageView.image;
CGSize imageSize = image.size;
CGRect imageRect = CGRectMake(0, 0, imageSize.width, imageSize.height);
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.0);
// Create the clipping path and add it
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:imageRect];
[path addClip];
[image drawInRect:imageRect];
UIImage *roundedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.imageView.image = roundedImage;
以下但现在我还需要添加它周围的圆形边框。我是否需要一个新的路径,或者我可以在上面的代码中添加一个?
[imageView.layer setBorderColor:[的UIColor blackColor ] CGColor]]; [imageView.layer setBorderWidth:1.0]; [imageView.layer setCornerRadius:10.0f];如果你像这样设置边界会发生什么?它工作吗? – iDev
这段代码将一个边框添加到'imageView'图层,而不是剪裁和包含的图像。 – atxe
这将工作,如果你设置imgView.clipsToBounds = YES; – Allfocus