我有一个自定义单元格,当用户选择该单元格时,我希望两个 UILabels 中的文本更改为浅灰色。
ChecklistCell.h:
#import <UIKit/UIKit.h>
@interface ChecklistCell : UITableViewCell {
UILabel *nameLabel;
UILabel *colorLabel;
BOOL selected;
}
@property (nonatomic, retain) IBOutlet UILabel *nameLabel;
@property (nonatomic, retain) IBOutlet UILabel *colorLabel;
@end
ChecklistCell.m:
#import "ChecklistCell.h"
@implementation ChecklistCell
@synthesize colorLabel,nameLabel;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)dealloc {
[nameLabel release];
[colorLabel release];
[super dealloc];
}
@end
最佳答案
在您的 didSelectRowAtIndexPath
方法中,调用以获取当前单元格并相应地更新:
CheckListCell* theCell = (CheckListCell*)[tableView cellForRowAtIndexPath:indexPath];
theCell.nameLabel.textColor = [UIColor lightGrayColor];
theCell.colorLabel.textColor = [UIColor lightGrayColor];
关于iphone - 更改自定义 UITableViewCell iphone 中的文本颜色,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2862193/