我有一个包含 UIImage 和 UILabel 的单元格:
我有这段代码来设置它的内容,非常标准的东西:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *itemCellID = @"menuItem";
NSString *currentMenuLabel = [self.menuItemStructure objectAtIndex:[indexPath row]];
NSString *currentMenuIcon = [self.menuItemIcon objectAtIndex:[indexPath row]];
MTNLeftMenuItemCell *cell = [self.tableView dequeueReusableCellWithIdentifier:itemCellID];
[cell.leftMenuItemLabel setText:currentMenuLabel];
UIImage *icon = [UIImage imageNamed:currentMenuIcon];
[cell.leftMenuItemIcon setImage:icon];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
现在我想做的是在点击单元格时更改此 UILabel 的
文本颜色,有点像 .cell .label:hover { ... }
CSS。回想起来这似乎很明显,但让我感到困惑的是 UILabel
作为单元格的 subview 。
我该怎么做?
最佳答案
有一个委托(delegate) didSelectRowAtIndexPath
方法在选择单元格时调用
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; //Get your cell for selected row
cell.leftMenuItemLabel.textColor = [UIColor redColor];//Configure whatever color you want
}
关于ios - 点击单元格时更改表格单元格内 UILabel 的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24604964/