Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImageView cover entire UITableViewCell using aspect fill

In the interface builder, I'm trying to create a prototype cell with an image that covers the entire cell but it is not running how it is expected.

As you can see in the following screenshot of my interface builder, I have an image view covering the entire cell, and is constrained to each edge of the cell:

enter image description here

And in fact this is how I expect it to look on the simulator, but instead I get this:

enter image description here

Where as you can see, it is not anchored all the way to the sides, and it may be hard to see, but the image actually extends past the bottom of the cell (if you look hard enough you can see the separator striking through the bottom portion of the image.

This is really buggy and I really have no idea what's happening.

like image 648
rigdonmr Avatar asked Oct 30 '22 10:10

rigdonmr


1 Answers

Perhaps adding aUIImageView inside of your cell in code.

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    //configure cell
    let imageView = UIImageView(frame: self.cell.frame)
    imageView.image = YOUR_IMAGE
    imageView.center = cell.center
    imageView.frame.size = cell.frame.size
    imageView.contentMode = .ScaleAspectFill
    cell.addSubview(imageView)
}

Hope this helps.

like image 131
Pranav Wadhwa Avatar answered Nov 08 '22 06:11

Pranav Wadhwa