我想通过 imageView 和 imageView 层为 TVC 单元格的图像添加边框
我有适用于 cell.layer 本身的代码,但是一旦我将其更改为 cell.imageView.layer,代码就什么也不做。
我在 tableView:cellForRowAtIndexPath 中使用它,并且在 Xcode 4.6.3、iOS 6.x 中
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.imageView.image = [UIImage imageNamed:@"myImage.png"];
CALayer* layer;
//layer = cell.layer;
layer = cell.imageView.layer;
[layer setMasksToBounds:YES];
[layer setCornerRadius:10.0f];
[layer setBorderWidth:10.0f];
如果应用于 cell.layer,这将有效,但对单元格的 imageView.layer 没有任何作用。
有任何想法吗?
谢谢。
编辑:仅供引用,我正在导入
<QuartzCore/QuartzCore.h>
.编辑:虽然这对单元格有效,但那是因为单元格已经有一个定义为黑色的边框颜色。 imageView 没有,因此需要像这样设置边框颜色:
[cell.imageView.layer setBorderColor: [[UIColor whiteColor] CGColor]];
[cell.imageView.layer setBorderColor: [[UIColor blackColor] CGColor]];
[cell.imageView.layer setBorderColor: [[UIColor colorWithRed:.5f green:.6f blue:.3f alpha:.75f] CGColor ]];
最佳答案
另一种选择是,添加
#import <QuartzCore/QuartzCore.h>
框架和使用
cell.imageView.layer.borderWidth = 1.0f;
cell.imageView.layer.setMasksToBounds = YES;
关于ios - 在单元格的 imageView 中为图像添加边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18274565/