Mat*_*hew 7 objective-c quartz-graphics uiimageview ios
我有以下代码,使UIImageView我的每个UITableView的单元格都有圆角:
- (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!
}
Run Code Online (Sandbox Code Playgroud)
我希望图像之间有一点差距,并认为我可以利用边框宽度来实现这一点.下面是实际发生的事情的图像:

这是我想要知道如何摆脱的微弱的黑色边框.我想有一种方法可以使用边框宽度.如果没有,最好的方法可能只是调整图像本身的大小,并将边框宽度设置为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;
Run Code Online (Sandbox Code Playgroud)