2013-10-26 26 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更改標籤顏色:正如你可以看到我使用純文本。對於歸屬文本黑客無效。