PinLayout
PinLayout copied to clipboard
How do I auto-size the container of image view and label?
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()
Hi, do you have a graphic of what you are trying to achieve? This would helps me to give you an accurate answer.
Hi, Thanks a lot. This is the design of the question.
![Screen Shot 2022-02-16 at 10 54 32](https://user-images.githubusercontent.com/14102044/154188002-1be3acd2-8807-4629-8360-8ac9b2923e4a.png)
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.
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()
Any feedback? Else, please close this issue.
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.