私には習慣があります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;