我有一个带有自定义单元格的表视图。自定义单元格上有文本字段。
当单元格突出显示时,我希望将文本字段的文本颜色从白色更改为黑色。
我知道cell.textLabel.highlightedTextColor,但是有没有人能想出一种方法把它改成文本字段?
谢谢。
发布于 2014-06-15 12:37:06
您可以实现委托协议方法(可从iOS 6.0获得) tableView:shouldHighlightRowAtIndexPath:或tableView:didHighlightRowAtIndexPath:,具体取决于您的要求,以拦截用户的触摸并从中获取指向感兴趣的UITextField的指针。
下面的代码假设位于一个既是表视图委托又是数据源的对象中。
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
// get the cell by calling datasource protocol method
UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
// fast enumeration to get UITextField(s) from the cell
for (UITextField *textField in cell.subviews) {
// change color here...
textField.textColor = [UIColor redColor];
}
return YES;
}https://stackoverflow.com/questions/24225857
复制相似问题