MarqueeLabel is a functional equivalent to UILabel that adds a scrolling marquee effect when the text of the label outgrows the available width (for the given font size). All standard UILabel properties are available in MarqueeLabel and it behaves just like a UILabel.
MarqueeLabel supports moving the label at either a defined rate (points per second) or duration (seconds). The animation curve can also be defined, and defaults to UIViewAnimationOptionCurveEaseInOut
. It also features a variable-length fade at the left and right side view borders, in order to fade the label text into the background rather than simply being chopped off.
Import MarqueeLabel.h and replace your UILabels with MarqueeLabels.
Replace:
UILabel *lengthyLabel = [[UILabel alloc] initWithFrame:labelCGRectFrame];
With:
MarqueeLabel *scrollyLabel = [[MarqueeLabel alloc] initWithFrame:labelCGRectFrame duration:8.0 andFadeLength:10.0f];
This creates a MarqueeLabel that will scroll across its content in 8.0 seconds, and adds 10.0 point long fade at the left and right boundaries.
If you'd rather have a label that scrolls at a specific rate (points per second), instead of completing the scroll in a specific time frame, you can use this:
MarqueeLabel *scrollyLabel = [[MarqueeLabel alloc] initWithFrame:labelCGRectFrame rate:50.0 andFadeLength:10.0f];
See the included MarqueeLabelDemo project for further example usage.
- Any ideas?
Charles Powell
Give me a shout if you're using this in your project!