本文介绍了在自定义UITableViewCell iphone中更改文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义单元格,当用户选择该单元格时,我希望两个UILabel中的文本更改为浅灰色。

I have a custom cell and when the user selects that cell, I would like the text in the two UILabels to change to light gray.

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 方法中,拨打电话获取当前单元格并进行相应更新:

In your didSelectRowAtIndexPath method, make a call to get the current cell and update accordingly:

CheckListCell* theCell = (CheckListCell*)[tableView cellForRowAtIndexPath:indexPath];
theCell.nameLabel.textColor = [UIColor lightGrayColor];
theCell.colorLabel.textColor = [UIColor lightGrayColor];

这篇关于在自定义UITableViewCell iphone中更改文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 20:10