Using UIviewrepresentable to Wrap Marqueelabel View

Using UIViewRepresentable to wrap MarqueeLabel view

It is by-default expanded by intrinsic content to full width, so MarqueeLabel just does not have what to scroll - everything is in frame.

In such cases we need to give ability to parent to shrink internal view to externally available space (by width in this case to screen)

so here is a fix - decrease resistance priority:

func makeUIView(context: UIViewRepresentableContext<UILabelView>) -> MarqueeLabel {

let label = MarqueeLabel()
label.text = text
label.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
// ^^^^^ << this one !!
return label

}

demo

Tested with Xcode 13.4 / iOS 15.5

How to find the frame of a SwiftUI UIViewRepresentable

It is due to use of GeometryReader

Try to use

custonView(model:self.model)
.fixedSize()


Related Topics



Leave a reply



Submit