Search code examples
iosuitableviewtableviewautoresizeaccessory

TableViewCell squeezes subviews when adding accessory in Swift 3


I'm having a problem with my UITableViewCell.

Table View Cell

These are two users in my social network app. After fetching the users from the server, I check if my user is following them currently. If yes, I'm adding the checkmark to the cell.

As you can see, in the upper cell adding the checkmark squeezes the imageView und moves the two Labels to the left in comparison the the bottom cell. I've tried solving this problem like that:

cell.autoresizesSubviews = false

But it doesn't work. I'm kind of stuck with this problem currently, does anybody have a suggestion how to solve it? Thanks!


Solution

  • How are your trailing constraints set for those labels? Setting them to be = 8 to leading edge of your imageView will allow them to stretch all the way to 8 points away from the imageView. Also keep in mind if you are already doing this, and setting the imageView's view.frame.width = 0 if the check mark isn't going to be present, would also cause the difference in the views.

    You could set the imageView.isHidden = true to keep the views looking the same.