如何删除UIImageView上带有圆角和边框宽度的黑边?

我有以下代码使我的每个UITableView单元格中的UIImageView都有圆角:

 - (void)awakeFromNib { // Rounded corners. [[cellImage layer] setCornerRadius:([cellImage frame].size.height / 2)]; [[cellImage layer] setMasksToBounds:YES]; [[cellImage layer] setBorderColor:[[UIColor whiteColor] CGColor]]; [[cellImage layer] setBorderWidth:3]; // Trouble! } 

我希望图像之间有一点差距,并认为我可以利用边框宽度来实现这一点。 下面是实际发生的事情的图像:

具有严重渲染圆角的用户列表

这是我想要知道如何摆脱的微弱的黑色边框。 我想有一种方法可以使用边框宽度。 如果没有,最好的方法可能只是调整图像本身的大小,并将边框宽度设置为0。

您可以为遮罩创建贝塞尔曲线路径,为该路径创建形状图层,然后为图像视图的图层蒙版指定该形状图层,而不是使用圆角半径:

 CGFloat margin = 3.0; CGRect rect = CGRectInset(imageView.bounds, margin, margin); UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(imageView.bounds.size.width/2, imageView.bounds.size.height/2) radius:radius startAngle:0 endAngle:M_PI*2 clockwise:NO]; CAShapeLayer *mask = [CAShapeLayer layer]; mask.path = path.CGPath; imageView.layer.mask = mask; 

您正在做的是,您将轮廓图像和边框剪切在一起,这使得单元格的轮廓图像延伸通过边框。

你错过了这一行: –

 cellImage.clipsToBounds = YES; 
Interesting Posts