gpt4 book ai didi

ios - 自定义表格 View 单元格选择字体颜色

转载 作者:技术小花猫 更新时间:2023-10-29 10:58:11 25 4
gpt4 key购买 nike

我有一个自定义的 UITableViewCell。它内部有 3 个带有自定义文本的自定义标签。

当我点击单元格时,我希望所有这些标签的 textColor 变为白色。就像电子邮件应用程序 UITableViewCell 行为一样。

为此,我在自定义单元格类中编写了它。

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

// Configure the view for the selected state

if (self.selected) {
_subjectLabel.textColor = [UIColor whiteColor];
_messageLabel.textColor = [UIColor whiteColor];
_usernameLabel.textColor = [UIColor whiteColor];
}else {
_subjectLabel.textColor = [UIColor blackColor];
_messageLabel.textColor = [UIColor grayColor];
_usernameLabel.textColor = [UIColor blackColor];
}



}

我能够得到它。但它不像在电子邮件应用程序中那样流畅。颜色仅在一小段延迟后发生变化。我应该覆盖 UITableViewCell 的哪个方法来放入此代码。我知道以下选项,但它们不会将行为赋予自定义单元格中的自定义标签。

typedef enum {
UITableViewCellSelectionStyleNone,
UITableViewCellSelectionStyleBlue,
UITableViewCellSelectionStyleGray
} UITableViewCellSelectionStyle;

最佳答案

设置标签的高亮文本颜色,这一切都会自动为您完成。您根本不需要在 setSelected 中做任何特殊的事情。

例如

_subjectLabel.highlightedTextColor = [UIColor whiteColor];

关于ios - 自定义表格 View 单元格选择字体颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10663039/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com