Home > Net >  Using UIViewRepresentable to wrap MarqueeLabel view
Using UIViewRepresentable to wrap MarqueeLabel view

Time:07-05

I have a simple UIViewRepresentable of a MarqueeLabel, but it does not work. My guess is that the frame is not correctly set, but I don't know what to pass to the MarqueeLabel initialiser as a frame. Using geometry Reader or some other way to get the Marquee effect is not an option.

struct UILabelView : UIViewRepresentable {
    
    var text: String

    typealias UIViewType = MarqueeLabel

    func makeUIView(context: UIViewRepresentableContext<UILabelView>) -> MarqueeLabel {
        
        let label = MarqueeLabel()
        print(label.frame.size)
        label.text = text
        return label
        
    }
    
    func updateUIView(_ uiView: MarqueeLabel, context: UIViewRepresentableContext<UILabelView>) { }
    
}

I have tried using demo

Tested with Xcode 13.4 / iOS 15.5

  • Related