2013-10-26 29 views
2

我想把选取框标签中的UITableView细胞,但与costomized像标签的文字是不同的颜色我想把选取框标签不同的标签的文本颜色

我使用MarqueeLabel类和我能够显示字幕标签在UITableViewCell上,它是完美的工作。

我也试过NSAttributedString但MarqueeLabel不支持不同颜色的标签文本的

如果有人有答案,那么请给我

感谢。

这里是我的代码

[cell.contentView addSubview:[self createMarqueeLabelWithIndex:indexPath.row]]; 

[cell.textLabel setTextColor:[UIColor redColor] range:NSMakeRange(4, 3)]; 

-(MarqueeLabel *)createMarqueeLabelWithIndex:(int)index 
{ 

    MarqueeLabel *continuousLabel2 = [[MarqueeLabel alloc] initWithFrame:CGRectMake(10,0,300,30) rate:50.0f andFadeLength:10.0f]; 
    continuousLabel2.marqueeType = MLContinuous; 
    continuousLabel2.continuousMarqueeSeparator = @""; 
    continuousLabel2.animationCurve = UIViewAnimationOptionCurveLinear; 
    continuousLabel2.numberOfLines = 1; 
    continuousLabel2.opaque = NO; 
    continuousLabel2.enabled = YES; 
    continuousLabel2.shadowOffset = CGSizeMake(0.0, -1.0); 
    continuousLabel2.textAlignment = UITextAlignmentLeft; 
    continuousLabel2.backgroundColor = [UIColor clearColor]; 
    continuousLabel2.font = [UIFont fontWithName:@"Helvetica-Bold" size:17.000]; 

    NSString *strText = [[arrTicker objectAtIndex:index] objectForKey:@"text"]; 
    NSString *strTime = [[arrTicker objectAtIndex:index] objectForKey:@"time"]; 
    NSString *strUser = [[arrTicker objectAtIndex:index] objectForKey:@"userid"]; 

    NSString *strTemp = [NSString stringWithFormat:@"%@ %@ %@ ",strText,strTime,strUser]; 

    continuousLabel2.text = [NSString stringWithFormat:@"%@",strTemp]; 

    return continuousLabel2; 
} 
+0

POst你的一些代码。 – user1673099

+0

我发布了代码 –

+0

编辑您用于支持来自属性字符串的颜色的选取框标签源代码。然后提出一个拉请求给这个颜色支持回社区。 –

回答

3

在您的cellforrowatindexpath中创建uilabel并将您的标签设置为比将uilabel的文本设置为属性字符串并将uilabel转换为标签并将子视图添加到您的单元格。

希望这会对你有所帮助。 谢谢。

1

没有最佳答案,而是一个肮脏的黑客。

后快速调查我刚刚加入[self setTextColor:[super textColor]];forwardPropertiesToSubLabel

- (void)forwardPropertiesToSubLabel { 
    // Since we're a UILabel, we actually do implement all of UILabel's properties. 
    // We don't care about these values, we just want to forward them on to our sublabel. 
    NSArray *properties = @[@"baselineAdjustment", @"enabled", @"font", @"highlighted", @"highlightedTextColor", @"minimumFontSize", @"shadowColor", @"shadowOffset", @"textAlignment", @"textColor", @"userInteractionEnabled", @"text", @"adjustsFontSizeToFitWidth", @"lineBreakMode", @"numberOfLines", @"backgroundColor"]; 
    for (NSString *property in properties) { 
     id val = [super valueForKey:property]; 
     [self.subLabel setValue:val forKey:property]; 
    } 
    [self setText:[super text]]; 
    [self setFont:[super font]]; 
    [self setTextColor:[super textColor]]; 
} 

现在我可以通过故事板编辑

Editing MarqueeLabel in Storyboard

NB更改标签颜色:正如你可以看到我使用纯文本。对于归属文本黑客无效。