【发布时间】:2015-05-22 00:27:49
【问题描述】:
我正在尝试缩小每个单元格中显示的图标的大小。我尝试使用的代码是:
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
let cellIcon = UIImage(named: tableIcons[indexPath.row])
cell.imageView!.frame = CGRect(x: cell.imageView!.frame.origin.x, y: cell.imageView!.frame.origin.y, width: cell.imageView!.frame.size.width / 2, height: cell.imageView!.frame.size.height / 2)
cell.imageView!.image = cellIcon
cell.imageView?.contentMode = UIViewContentMode.ScaleAspectFill
return cell
我原以为这会将图像视图缩小一半,并使图像比例填充现在减半的视图。但是单元格中的图像保持相同的大小。我是否正确地解决了这个问题?
【问题讨论】:
-
根据我的经验,如果您使用内置视图(imageView、textLabel、detailTextLabel)并尝试做任何花哨的事情来更改它们的大小,那么您将遇到无限麻烦。
-
如果图像视图是当前大小的一半,我认为你应该首先将宽度和高度设置为它的一半。另外,您可以尝试设置 cell.imageView?.clipsToBound = true
标签: ios swift cocoa-touch