Search code examples
iosswiftautolayoutsnapkit

ImageView stick to UILabel in UITableViewCell


I have problem to achieve this on SnapKit, I want that my ImageView should be stick to multi-line UILabel in UITableViewCell

It should work like on this image:

enter image description here

I tried something like this and this approach not working.

label.snp.makeConstraints { make in
    make.top.left.equalToSuperview()
}

imageView.snp.makeConstraints { make in
     make.size.equalTo(20.0)
     make.top.equalToSuperview()
     make.left.equalTo(label.snp.right).offset(5)
     make.right.greaterThanOrEqualToSuperview()
}

Solution

  • The image view should have: make.right.lessThanOrEqualToSuperview() so that it doesn't have to go all the way to the right of the superview, (which is probably centering your image somewhere between the label and the right of the superview, instead of floating to the left).