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.
Question
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.
OTHER TIPS
Not the best answer but rather a dirty hack.
After quick investigation I've just added [self setTextColor:[super textColor]];
to 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]];
}
Now I can change label color through storyboard editor
NB: As you can see I use plain text. For attributed text hack does not work.