Chu*_*eow 13 iphone cocoa-touch objective-c uitableview
我在UITableView的单元格中添加了一个文本阴影,给它们一个蚀刻的外观:
cell.textLabel.textColor = [UIColor colorWithWhite:0.2 alpha:1.000];
cell.textLabel.shadowColor = [UIColor whiteColor];
cell.textLabel.shadowOffset = CGSizeMake(0, 1);
Run Code Online (Sandbox Code Playgroud)
由于阴影颜色实际上是白色,当一行被选中并变为蓝色时,白色阴影变得非常明显并使文本看起来很难看.
有没有人知道如何在应用默认单元格选择样式之前删除阴影?
我试过了:
-tableView:willSelectRowAtIndexPath:取消设置的阴影cell.textLabel.shadowColor = nil,但这不按时上班-阴影未设置得到应用了蓝色选择样式之后.cell.selected中tableView:cellForRowAtIndexPath:设置的阴影之前,但这显然是行不通的,因为电池是不是一个选择后重绘.我也试过覆盖-tableView:willDisplayCell:forRowAtIndexPath:委托方法,正如Kevin在下面提到的那样.从我输入的日志语句中,这个委托方法仅在绘制单元格之前调用 - 在触摸单元格时,它已经太晚了.这是我使用的代码
(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"in willDisplayCell");
if (cell.highlighted || cell.selected) {
NSLog(@"drawing highlighed or selected cell");
cell.textLabel.shadowColor = nil;
} else {
cell.textLabel.shadowColor = [UIColor whiteColor];
}
}
Run Code Online (Sandbox Code Playgroud)
Mik*_*ead 35
应该工作的一种方法是扩展UITableViewCell并覆盖setSelected AND setHighlighted方法,相应地设置投影状态.这将确保它与背景突出显示更新同时绘制.
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
[super setHighlighted:highlighted animated:animated];
[self applyLabelDropShadow:!highlighted];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
[self applyLabelDropShadow:!selected];
}
- (void)applyLabelDropShadow:(BOOL)applyDropShadow
{
self.textLabel.shadowColor = applyDropShadow ? [UIColor whiteColor] : nil;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8192 次 |
| 最近记录: |