Search code examples
iosswiftswift2tableviewsdwebimage

how can i keep image size in tableview?


This is what I get when I launch my app

enter image description here

after I click on the cell the images get bigger

enter image description here

My Code is like this

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("myCell", forIndexPath: indexPath)


    // Configure the cell...
    cell.imageView?.sd_setImageWithURL(NSURL(string: imageArray[indexPath.row]), placeholderImage:UIImage(named: "pin.png"))

  cell.imageView?.frame = CGRectMake(0, 0, 50, 50)
    return cell
}

imageArray is just string of image URLs. Please help

thanks in advance


Solution

  • You can try to use the contant mode property:

    imageViewObject.contentMode = UIViewContentMode.ScaleToFill
    

    or

    imageViewObject.contentMode = UIViewContentMode.ScaleAspectFit
    

    or

    imageViewObject.contentMode = UIViewContentMode.ScaleAspectFill