Skip to content

How to wrap MarqueeLabel with using SwiftUI? #281

@sudachi808

Description

@sudachi808

I want to use MarqueeLabel within SwiftUI views.
But I could not work it using the code below.

How do I implement it?

import SwiftUI
import MarqueeLabel

struct MarqueeText: UIViewRepresentable {
        
    func makeUIView(context: Context) -> MarqueeLabel {
        MarqueeLabel(frame: .init(x: 0, y: 0, width: 100, height: 24), duration: 1.0, fadeLength: 10.0)
    }
    
    func updateUIView(_ uiView: MarqueeLabel, context: Context) {
        uiView.textAlignment = .center
        uiView.text = "The quick brown fox jumps over the lazy dog."
        uiView.restartLabel()
    }
}

// MARK: - Preview

struct MarqueeText_Previews: PreviewProvider {
    static var previews: some View {
        MarqueeText()
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions