hfz*_*hfz 2 objective-c uitableview uilabel ios
我有一个内置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;
}
Run Code Online (Sandbox Code Playgroud)
现在我要做的是UILabel's在点击单元格时更改此文本颜色,有点像.cell .label:hover { ... }css.回想起来,这似乎相当明显,但UILabel作为细胞的子视图让我感到困惑.
我怎样才能做到这一点?
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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1250 次 |
| 最近记录: |