如何在tableview中保持图像大小?

时间:2016-09-07 11:16:02

标签: ios swift swift2 tableview sdwebimage

这是我启动应用时的结果

enter image description here

点击单元格后,图像变大了

enter image description here

我的代码就像这样

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只是图片网址的字符串。请帮忙

提前致谢

3 个答案:

答案 0 :(得分:1)

您可以尝试使用内容模式属性:

imageViewObject.contentMode = UIViewContentMode.ScaleToFill

imageViewObject.contentMode = UIViewContentMode.ScaleAspectFit

imageViewObject.contentMode = UIViewContentMode.ScaleAspectFill 

答案 1 :(得分:0)

尝试在sd_setImageWithURL

的完成闭包中设置框架
cell.imageView?.sd_setImageWithURL(NSURL(string: "Your URL")!, placeholderImage: nil) { (image, error, cache, url) in
    cell.imageView?.frame = CGRectMake(0, 0, 50, 50)
}

希望这有帮助。

答案 2 :(得分:0)

视图必须更大,然后原始图片视图现在提供 backgruond颜色 来查看并在该视图中提供图片图即可。它可能看起来像图像的固定大小,但有背景。