【发布时间】:2018-05-16 04:55:42
【问题描述】:
我有一个带有自定义单元格的 UITable,每个单元格都有一个 uiimage。当我突出显示单元格时,图像没有突出显示。
为了突出显示单元格的图像,当我在表格中选择一个单元格时,会调用didHighlightRowAtIndexPath。在该方法中,我更改了单元格的背景颜色。我还调用了一个方法,indicatedImageViewPressed、which I got from this post,为单元格的图像添加叠加层。
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
// Add your Colour.
SpeciesCell* speciesCell = (SpeciesCell*)[tableView cellForRowAtIndexPath:indexPath];
speciesCell.contentView.backgroundColor = [UIColor colorWithWhite:0.17 alpha:1.000];
speciesCell.backgroundColor = [UIColor colorWithWhite:0.17 alpha:1.000];
speciesCell.speciesImage.backgroundColor = [UIColor colorWithWhite:0.17 alpha:1.000];
[self indicatedImageViewPressed:speciesCell.imageView on:YES];
}
- (void)indicatedImageViewPressed:(UIImageView *)imageView on:(BOOL)on {
UIView *overlay = [imageView viewWithTag:1]; // See if already created
if (overlay == nil) {
overlay = [[UIView alloc] initWithFrame:imageView.frame];
overlay.tag = 1; // Mark view to find it next time
overlay.backgroundColor = [UIColor colorWithWhite:0.17 alpha:1.000]; // Your color overlay goes here
[imageView addSubview:overlay];
[imageView bringSubviewToFront:overlay];
}
overlay.hidden = !on;
}
但是,单元格的图像不会改变。不添加叠加层。我尝试bringSubviewToFront 以确保覆盖没有被其他视图遮挡,但它仍然不起作用。
更新:我可以为 speciesCell.speciesImage 添加边框宽度/颜色
【问题讨论】:
-
仅出于调试目的,在 didHighlightRowAtIndexPath 方法中为 speciesCell.speciesImage 添加边框宽度和边框颜色红色,并让我知道它是否在图像上显示边框
-
@MuhammedIrfan 边框确实出现在 speciesCell.speciesImage 上!
-
嗯,这是个问题
-
你看到你的添加层代码没有问题
-
@Matt 在我看来,更改图像的
alpha或opacity是一种更简单的方法,您不会遇到此问题。
标签: ios objective-c uitableview uiimageview addsubview