MarqueeLabel is very easy to use label. Using CABasicAnimation to implement.
Just run the example project, or clone the repo.
- Xcode 12 or above
- iOS 14
- Swift 5
- Setp 1. In storyboard, drop a UILabel into viewController.
- Setp 2. Select [Show the Identity inspector] in right side panel.
- Setp 3. Change class to [MarqueeLabel] in Custom Class
- Setp 4. Create Referencing Outlets
- Setp 5. Setting text
// Create new label
let label = MarqueeLabel()
// Set up default style
label.style = DefaultStyle()
// Set up the text using default property
lable.text = "Stay Hungry. Stay Foolish. And I have always wished that for myself."
// Update the text color using default property
label.textColor = .blue
// Update the text font using default property
label.font = .preferredFont(forTextStyle: .title1)
- Setp 6. Build and run!
// the style must be init with text
var style1 = DefaultStyle()
// need show full text or not
style1.showFullText = true
// set back color
style1.backColor = .clear
// set whether to end the animation with transparency
style1.opacityInTheEnd = true
// set marquee time
style1.duration = 10
Implement this protocol if you need tap event, like as:
self.demoLabel.delegate = self
extension ViewController:MarqueeLabelProtocol {
func tap(sender: MarqueeLabel) {
//Do something...
}
}
Licence MIT