how to implement marquee label in IOS using swift
For creating marquee in swift Add Below Class in your Project https://github.com/cbpowell/MarqueeLabel
To do this first add the pod: pod 'MarqueeLabel'
.
And perform a pod update
in your project.
Create one label and set the custom class as MarqueeLabel
in the storyboard.
Then:
@IBOutlet weak var marqueeLabel:MarqueeLabel!
In ViewDidLoad add this:
marqueeLabel.type = .Continuous
marqueeLabel.scrollDuration = 5.0
marqueeLabel.animationCurve = .EaseInOut
marqueeLabel.fadeLength = 10.0
marqueeLabel.leadingBuffer = 30.0
marqueeLabel.trailingBuffer = 20.0
Use MarqueeLabel, it very easy to use & implement.
If you are using Pod then you can integrate and try sample code as:
Objective-C:
pod 'MarqueeLabel'
MarqueeLabel *lengthyLabel = [[MarqueeLabel alloc] initWithFrame:aFrame duration:8.0 andFadeLength:10.0f];
Swift:
pod 'MarqueeLabel/Swift'
var lengthyLabel = MarqueeLabel.init(frame: aFrame, duration: 8.0, fadeLength: 10.0)
Another Solution Using Web View:
String marquee = "<html><body><marquee>This is sample marquee</marquee></body></html>"
webview.loadData(marquee, "text/html", null);
Here is result:
Download the following link github Marquee label Demo:
https://github.com/cbpowell/MarqueeLabel-Swift
then
Follow the following steps :
Download the above github Project
Copy Marqueelabel.swift file from classes
paste Marqueelabel.swift file in your project
Give your any UILabel as MarqueeLabel type
Ex : @IBOutlet weak var demoLabel1: MarqueeLabel!
Run You project