我有一個自定義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;
謝謝。有效! – Anand
只需稍微提醒一下,如果單元格是自定義單元格,則可以打開xib並在屬性檢查器下,可以設置「突出顯示」顏色。 –