0
我有一个自定义单元格,带有图像视图和标签。当用户在桌面视图中选择特定的单元格时,我想更改它的图像和标签字体颜色。我可以这样做吗?我想避免单元格选择的默认方式蓝色的单元格),并使用上面的方法,而不是那个。如何在uitableview中选择时更改自定义单元格图像和标签字体颜色?
我有一个自定义单元格,带有图像视图和标签。当用户在桌面视图中选择特定的单元格时,我想更改它的图像和标签字体颜色。我可以这样做吗?我想避免单元格选择的默认方式蓝色的单元格),并使用上面的方法,而不是那个。如何在uitableview中选择时更改自定义单元格图像和标签字体颜色?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MyCustomCell *selectedCell = (MyCustomCell *)[tableView cellForRowAtIndexPath:indexPath];
//selectedCell.textLabel.textColor = <#your color#>
//selectedCell.myImage = <#your image>
}
如果你想改变选中的单元格backgroundColor,试试这个。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellId = @"cellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
if(!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
UIView *bgColorView = [[UIView alloc] init];
[bgColorView setBackgroundColor:[UIColor redColor]];
[cell setSelectedBackgroundView:bgColorView];
}
}
谢谢,我已经做了this.But当我选择另一小区,则首先选择单元和第二选择单元格都具有突出image.I想避免that.I想要的缺省小区选择行为(当我选择第一个单元格后选择另一个单元格时,第一个单元格图像应该是正常图像,第二个单元格图像应该是高亮显示的图像)我该怎么做到这一点? – harshiYL 2013-02-10 16:27:34
我得到它通过使用完成 - (无效)的tableView:(UITableView的*)的tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {//selectedCell.textLabel.textColor = <#your颜色#> //selectedCell.myImage = <#your image> }然后,我可以取消单元格取消后的正常图像 – harshiYL 2013-02-10 17:34:09