iphone - 如何更改突出显示状态下的 UITableViewCell 文本颜色?

标签 iphone objective-c cocoa-touch uitableview

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
    if (selected) {
        companyLabel.textColor = [UIColor whiteColor];
        priceLabel.textColor = [UIColor whiteColor];
        changeLabel.textColor = [UIColor whiteColor];
        symbolLabel.textColor = [UIColor whiteColor];
    }
    else
    {
        companyLabel.textColor = [UIColor blackColor];
        priceLabel.textColor = [UIColor blackColor];
        symbolLabel.textColor = [UIColor blackColor];

        if([changeLabel.text doubleValue] < 0)
        {
           changeLabel.textColor = [UIColor colorWithRed:239.0/255.0 green:16.0/255.0 blue:52.0/255.0 alpha:1.0];
        }
        else if([changeLabel.text doubleValue] > 0)
        {
           changeLabel.textColor = [UIColor colorWithRed:77.0/255.0 green:161.0/255.0 blue:0.0 alpha:1.0];
        }
    }

}

在下一个 View 被推送到导航堆栈之前,我的文本不会变白。

我希望它在用户点击并按住一个单元格时变成白色。

最佳答案

UILabel 有一个 highlightedTextColor 属性。当像 UITableViewCell 这样的 View 进入其突出显示状态时,所有 subview (包括您的标签)都应自动更改为使用其突出显示的属性。如果它仍然无法正常工作,也有一个用于禁用该功能的字段,您需要检查一下。

关于iphone - 如何更改突出显示状态下的 UITableViewCell 文本颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7197746/

相关文章:

iphone - 是否可以使用 Core Animation 淡出 UIBarButtonItem?

iphone - 特定角的角半径

iphone - 如何从iphone IOS上的时间间隔解析和提取年,月,日等

iphone - 我尝试使用 NSHost,但 XCode 无法识别它

ios - 使用点击手势时如何获取 UICollectionView header 的索引路径?

ios - ImagePicker 崩溃 - 使用 AutoLayout 时从库中选择图像并在 UIImageView 中设置

iphone - 打开和关闭 NSLogs 的正则表达式?

ios - 是否可以检查某个联系人是否存在于 iPhone 的联系人列表中?

iphone - 用于从accessoryButton 继续的索引路径

ios - 带有 : Static Cells with dynamic content and dynamic cells 的 UITableView