how to implement marquee label in IOS using swift
Asked Answered
M

6

10

How to implement MarqueeLabel in iOS. I found example in Objective-C but I'm using Swift.

Magus answered 8/10, 2015 at 5:6 Comment(1)
Try light weight library for marquee label in swift 3.0 github.com/Sahilberi/SwiftyScrollingLabelTadzhik
J
17

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.

Then import pod in your working file: import MarqueeLabel

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
Jd answered 8/10, 2015 at 7:55 Comment(0)
C
4

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:

enter image description here

Commorancy answered 8/5, 2017 at 16:35 Comment(0)
M
2

Download the following link github Marquee label Demo:

https://github.com/cbpowell/MarqueeLabel-Swift

then

Follow the following steps :

  1. Download the above github Project

  2. Copy Marqueelabel.swift file from classes

  3. paste Marqueelabel.swift file in your project

  4. Give your any UILabel as MarqueeLabel type

    Ex : @IBOutlet weak var demoLabel1: MarqueeLabel!

  5. Run You project

Matronage answered 8/10, 2015 at 5:37 Comment(1)
i fix the errors that error are difference between swift 1 and 2 thanks for your help.Magus
F
2

Using a label which can Marquee up its content is really simple. Just add MarqueeLabel pod in your project.

Swift:

pod 'MarqueeLabel/Swift'

And then select the label you wish to perform Marquee on and add the Custom Class MarqueeLabel to it in the Identity Inspector.

That's it.

This is the Simplest way to add marquee in your Label. After adding Custom Class MarqueeLabel if you want some spacing in between the last character and the first character of the content of your label then:

Step 1: Select the label.

Step 2: Go to Attributes Inspector and then increase the fadeLength attribute value the much you want to have. Applying value 10 to it is fair enough.

If you wish to customize more then Add custom class MarqueeLabel to the Label and then take the outlet of that Label in you Code and customize it the way you want to.

The outlet of that Label in your code should look like this:

@IBOutlet var YOURLABELNAME: MarqueeLabel!

If not so then start over by first adding the custom class to the label and then taking its outlet in the code file.

Frequentative answered 19/12, 2017 at 12:19 Comment(0)
C
0

Check out the Swift version of MarqueeLabel!

Casemaker answered 8/10, 2015 at 5:14 Comment(1)
This library is deprecated.Cornute
B
0

In Apple tvOS set speed like this by using MarqueeLabel

https://github.com/cbpowell/MarqueeLabel

previously speed set in my project

videoTitleLabel.speed = .duration(25.0)

Now I changed 25.0 to 10

videoTitleLabel.speed = .duration(10)

Now it moving bit speed

Boggs answered 6/10, 2021 at 7:33 Comment(2)
This library has an issue when restarting the scrolling.Iodate
@Iodate you can call restart method on your own.Circumambulate

© 2022 - 2024 — McMap. All rights reserved.