PinLayout icon indicating copy to clipboard operation
PinLayout copied to clipboard

How do I auto-size the container of image view and label?

Open KhazanGu opened this issue 2 years ago • 5 comments

I wanna a view containing an imageView and a label. But I don't know how to auto size the container. Because the number of lines with the label are undecided in the different devices. Please help me.

        self.imageView.pin.width(48).height(48).vCenter()
        self.label.pin.below(of: self.imageView).left(20).right(20).sizeToFit(.width)
        self.containerView.pin.wrapContent().center()

KhazanGu avatar Feb 15 '22 07:02 KhazanGu

Hi, do you have a graphic of what you are trying to achieve? This would helps me to give you an accurate answer.

lucdion avatar Feb 15 '22 12:02 lucdion

Hi, Thanks a lot. This is the design of the question.

Screen Shot 2022-02-16 at 10 54 32

The designer requested the imageView and the label should at the view center. So I defined a container with an imageView and a label, I just have no idea to auto-size the container. Thanks again.

KhazanGu avatar Feb 16 '22 03:02 KhazanGu

If the views hierarchy is:

SectionView (white view with rounded corners)
     ContainerView 
           ImageView
           Label

I think this should work, but I haven't tested

// Set the container's width to match the parent's width, so that imageView is centered correctly
self.containerView.pin.horizontally();  

self.imageView.pin.size(48).vCenter()

self.label.pin.below(of: self.imageView).left(20).right(20).sizeToFit(.width)

self.containerView.pin.wrapContent().center()

lucdion avatar Feb 16 '22 16:02 lucdion

Any feedback? Else, please close this issue.

lucdion avatar Feb 23 '22 14:02 lucdion

I'm so sorry about not responding for a long time. Because of something I asked for leave, I will check it after that. Thank you a lot.

KhazanGu avatar Feb 25 '22 14:02 KhazanGu