Forum Archive

Image after String in UI

psyFi

I'm making a today widget that shows a number (unknown number of digits) with an image beside the number.
Using frames, I can place the ImageView next to my Label, but I'd like the image to hug the contents of the label.
I've tried adding the image view as a subview to the label, using flex, and hard coded paths. Can anyone please help me out on this?

If I know how to get the width in pixels of the number string, I can adjust the frame accordingly, but I don't know how to do that either.

cvp

@psyFi Try ui.measure_string

mikael

@psyFi, call size_to_fit on the label. Your enclosing view probably needs to be custom so that you can implement the layout method where you first size the label and then position the image. If your text changes a lot, you might also implement a text property for the enclosing class, where you can set the label text and then call size_to_fit on the enclosing view, or just the repositioning code directly.