【发布时间】:2015-06-14 09:10:33
【问题描述】:
我有一个带有标识符“Cell”的 ViewController tableView。这是我的代码:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
var url = NSURL(string: postCover[indexPath.row])
let data = NSData(contentsOfURL: url!) //make sure your image in this url does exist, otherwise unwrap in a if let check
cell.imageView?.contentMode = .ScaleAspectFit
cell.imageView?.clipsToBounds = true
cell.imageView?.image = UIImage(data: data!)
cell.textLabel?.text = postTitle[indexPath.row]
cell.imageView?.layer.cornerRadius = 20
cell.imageView?.layer.masksToBounds = true;
return cell
}
所以,cornerRadius 有效,但问题之一是我在单元格中的图像 (cell.imageView?.image) 高度等于行高,我无法更改此单元格图像的高度和宽度。
当我尝试时
cell.imageView?.frame.size.width = 100
没有任何变化。谁知道,有什么问题?
由于我无法控制图像的高度和宽度,我得到的结果是带有边框半径的矩形,但我想要一个正方形(w:100,h:100)。
【问题讨论】:
-
你到底想要什么,圆形图像还是正方形?
-
尝试使用
heightForRowAtIndexPath -
@AnilVarghese 通告。我确实解释过,现在我得到了带有边框半径的矩形。所以我必须有正方形才能使用cornerRadius并获得圆形图像
-
@VNJ 不,我已经设置了行高。我想要例如:我的行高度 = 100,但单元格内的图像高度和宽度将:高度:80,宽度:80
-
能不能看一下屏幕截图,让大家有个清晰的思路?
标签: ios uitableview swift