thank_you
thank_you

Reputation: 11107

Prevent Image Overlaps in Table View Cell

In my cellForRowAtIndexPath method I have the following code.

    var cell = tableView.dequeueReusableCellWithIdentifier("Media Item", forIndexPath: indexPath) as MediaItemTableViewCell

    let mediaItem = tweet!.media[indexPath.row]

    let imageData = NSData(contentsOfURL: mediaItem.url)

    if imageData != nil {
        cell.mediaImage = UIImage(data: imageData!)
    } else {
        cell.mediaImage = nil
    }

    return cell

When I run this code my image overlaps over the TableViewCell.

enter image description here

I would love to have the image become thumbnail size and not overlap the bounds of the TableViewCell. What would be the best way to approach this? I've tried resizing the image but the image still becomes clipped. Thanks.

Upvotes: 0

Views: 758

Answers (2)

M_Waly
M_Waly

Reputation: 241

in my opinion the different dynamic image sizes worked by adding NSAutoLayoutConstraints to it relative to its height and width , you might face another problem that image is not centred correctly due to its size , which could be fixed by adding a proprtional NSAutoLayoutConstraint programtically to it then if you ever faced.

Upvotes: 0

Javier Flores Font
Javier Flores Font

Reputation: 2093

Have you marked aspect-fit in the UIImage and clipSubviews on MediaItemTableViewCell class in interfaceBuilder? (Attached image). enter image description here

Upvotes: 1

Related Questions