UIImage周围的上下边界

时间:2016-08-09 15:45:55

标签: ios objective-c cocoa-touch uiimage

UIImage内有UITableViewCell。 在UIImage周围设置上边框和下边框的最佳方法是什么?

[cell.backgroundImageView.layer setBorderColor: [[UIColor blackColor] CGColor]];
[cell.backgroundImageView.layer setBorderWidth: 2.0];    
cell.backgroundImageView.layer.frame = CGRectMake(0, 0, cell.backgroundImageView.layer.frame.size.width + 10, cell.backgroundImageView.layer.frame.size.height);

似乎没有效果。

2 个答案:

答案 0 :(得分:0)

边框属性管理整个图层的边框,而不是局部边框。

我会选择几个UIViews(根据需要设置背景颜色),使用autolayout固定到UIImageView并固定在单元格框架内。通过这种方式,您不会冒险在单元格范围之外绘制边框,或者让其他单元格内容与图像不对齐,因为图像看起来是一定的大小但实际上因为您一直在玩层。

答案 1 :(得分:0)

如果不考虑性能,可以在图像上方和下方添加高度为1px的UIView并设置其背景颜色。