cbpowell / MarqueeLabel

A drop-in replacement for UILabel, which automatically adds a scrolling marquee effect when the label's text does not fit inside the specified frame
MIT License
4.21k stars 564 forks source link

A string that is too long will cause the word to be cut in half at the end of the scrolling animation #220

Closed puhahalx closed 6 years ago

puhahalx commented 6 years ago

Usage Details

Expected Behavior

The loop rolls and works

Actual Behavior

When I put marqueelabel in a tableviewcell, I assigned a long string to marqueelabel, and the string was cut in half at the end of the scrolling animation. It did not end until all the characters were fully displayed, but ended early

Steps to Reproduce the Problem

1.in tableviewcell, _marqueeLabel=[[MarqueeLabel alloc]initWithFrame:CGRectMake(34, 0, WIDTH_K-70, self.height) rate:60 andFadeLength:10.0f]; _marqueeLabel.marqueeType=MLContinuous; _marqueeLabel.animationCurve = UIViewAnimationOptionCurveEaseInOut; _marqueeLabel.leadingBuffer=3; _marqueeLabel.textColor=[UIColor colorWithRed:0.13 green:0.18 blue:0.34 alpha:1.00]; _marqueeLabel.font=[UIFont systemFontOfSize:14]; [self addSubview:_marqueeLabel]; 2.Assign a long string to a marqueelabel 3.the string would be cut in half at the end of the scrolling animation

cbpowell commented 6 years ago

Unfortunately we found that the UILabel class has an upper limit on the view width, and if you exceed this maximum width it simply fails to display anything at all. So if you're using a really long text string, you're probably running into this limit, and there isn't a workaround other than to shorten your string.

Normally MarqueeLabel expands the underlying UILabel to the width necessary to hold all the text on one line, but there's no (easy) way around this basic width limit on the UILabel class. So to avoid the text disappearing entirely, I chose to have MarqueeLabel keep the max width of the text label below that limit. The effect is that any text past this max width will just be chopped off. You can see the code that enforces the limit here.

The limit is hardcoded though, and I haven't looked recently to see if the value has changed with recent iOS software and hardware releases. You could try adjusting the value to see if you can get more of your text without it truncating. When the label goes completely blank (no text), you know you've gone too far.