iOS清理圆angular轮廓图像的angular落

所以我遵循一个AppCoda教程围绕一个configuration文件图像的angular落,除了一件事,它运作良好。 无论图像是圆形还是圆形,图像都有一点渗透(特别是使用白色边框时)。

在这里输入图像说明

self.imageview.image = image self.imageview.layer.cornerRadius = 10.0 self.imageview.layer.borderWidth = 3.0 self.imageview.layer.borderColor = UIColor.whiteColor().CGColor self.imageview.clipsToBounds = true 

在这里输入图像说明

如果你想要的话,你也可以添加一个小小的面具:

 let path = UIBezierPath(roundedRect: CGRectInset(imageView.bounds, 0.5, 0.5), cornerRadius: 10.0) let mask = CAShapeLayer() mask.path = path.CGPath imageview.layer.mask = mask 

你可以在矩形上创build一个蒙版。 这似乎给了干净的边缘,至less在游乐场。 这里是代码,但是你需要修改它以获得圆angular的内部矩形。

 // simple red rect var view = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200)) view.backgroundColor = UIColor.redColor() view.layer.borderColor = UIColor.whiteColor().CGColor view.layer.borderWidth = 6.0 // path for the mask let rectanglePath = UIBezierPath(roundedRect:view.bounds, cornerRadius: 20) // applying the mask over the view let maskLayer = CAShapeLayer() maskLayer.frame = view.bounds maskLayer.path = rectanglePath.CGPath view.layer.mask = maskLayer 

一个简单的解决scheme就是可以将图层的边界放大一点以覆盖视图图像的边缘:

 CGFloat offset = 1.f; // .5f is also good enough self.imageview.image = image; self.imageview.layer.cornerRadius = 10.0; self.imageview.layer.borderWidth = 3.0 + offset; self.imageview.layer.borderColor = UIColor.whiteColor().CGColor; self.imageview.layer.masksToBounds = YES; [self.imageview.layer setBounds:CGRectMake(-offset, -offset, CGRectGetWidth(self.imageview.frame) + offset * 2.f, CGRectGetHeight(self.imageview.frame) + offset * 2.f)];