有待详细研究
iOS7: 只能显示 .titleLabel.textColor
<span style="color:#ff0000;">self.btnNum.titleLabel.textColor=[UIColor blueColor];</span>
iOS8: 只能显示 setTitleColor
<span style="color:#3366ff;">[self.btnNum setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];</span>
问题还未找到原由!有待观察。。。
代码如下:
//复用机制
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * cellName=@"cell";
HYHistoryCell * historyCell=[_tableViewHistory dequeueReusableCellWithIdentifier:cellName];
if (historyCell==nil){
historyCell=[[HYHistoryCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
historyCell.selectionStyle = UITableViewCellSelectionStyleNone;
}
NSDictionary * dic = [_arrRecord objectAtIndex:indexPath.row];
/*
* 期数
*/
historyCell.labelIssue.text=[NSString stringWithFormat:@"第%@期",dic[@"issueNum"]];
/*
* nums
*/
historyCell.arrayNum=dic[@"result"];
historyCell.boundaryNum = _boundaryNum;
[historyCell createButtons];
return historyCell;
}
//自定义cell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self){
// Initialization code
self.labelIssue=[[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, 30)];
self.labelIssue.text=@"期数";
self.labelIssue.textColor=[UIColor blackColor];
// self.labelIssue.backgroundColor=[UIColor grayColor];
self.labelIssue.font=[UIFont systemFontOfSize:15.f];
[self.contentView addSubview:self.labelIssue];
self.arrayBtn = [[NSMutableArray alloc] init];
}
return self;
}
-(void)createButtons
{
//移除之前赋值的btn
for (UIButton *button in self.arrayBtn) {
[button removeFromSuperview];
}
[self.arrayBtn removeAllObjects];
if ([self.arrayNum count]>0)
{
for (int i=0; i<[self.arrayNum count]; i++)
{
self.btnNum=[UIButton buttonWithType:UIButtonTypeCustom];
self.btnNum.enabled=NO;
self.btnNum.frame=CGRectMake(10+i*(BTNHEIGHT+2), 30, BTNWIDTH, BTNHEIGHT);
[self.btnNum setBackgroundImage:[UIImage imageNamed:@"small_circle_light"] forState:UIControlStateNormal];
[self.btnNum setTitle:[NSString stringWithFormat:@"%.2d",[[self.arrayNum objectAtIndex:i] intValue]] forState:UIControlStateNormal];
//根据界面判断字体模式
if ([_boundaryNum intValue] == 1) {
<span style="color:#ff0000;">self.btnNum.titleLabel.textColor=[UIColor blueColor];</span>
<span style="color:#3366ff;">[self.btnNum setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];</span>
if ([[self.arrayNum objectAtIndex:i] integerValue] == 19||[[self.arrayNum objectAtIndex:i] integerValue] == 20) {
<span style="color:#3366ff;">[self.btnNum setTitleColor:[UIColor redColor] forState:UIControlStateNormal];</span>
<span style="color:#ff0000;">self.btnNum.titleLabel.textColor=[UIColor redColor];</span>
}
}
else if([_boundaryNum intValue] == 2){
if (i < 6) {
[self.btnNum setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
}
else{
[self.btnNum setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
}
}
else if([_boundaryNum intValue] == 3){
[self.btnNum setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
}
[self.contentView addSubview:self.btnNum];
[self.arrayBtn addObject:self.btnNum];
}
}
}