Search code examples
iosxcodeuitableviewuilabelmarquee

I want to put Marquee Label with different label text color


I want to put Marquee Label in UITableView cell but with costomized like label text is different color

I am using MarqueeLabel Classes and I am able to display that Marquee Label on UITableViewCell and it is perfectly work.

I also tried for NSAttributedString but MarqueeLabel Does not support different color of label text

If anybody has answer then please give me

Thanks.

Here is my code

[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;
}

Solution

  • in your cellforrowatindexpath create uilabel and assign your marque label than uilabel's text set to attributed string and than convert uilabel to marque label and than add sub view to your cell.

    Hope this will be helpful for you. Thanks.