swift - 如何更改单元格中的 ImageView 大小?

标签 swift

我已设法更改单元格的行高,但现在用作图标的图像保持相同的大小,但现在太小了。我希望它的尺寸​​为 72x72,粘在单元格的左侧。

我在cellForRowAtIndexPath中使用以下内容:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = cellForTableView(tableView)
    let checklist = dataModel.lists[indexPath.row]
    cell.textLabel?.textColor = UIColor(red: 25.0/255.0, green: 25.0/255.0, blue: 112.0/255.0, alpha: 1.0)
    cell.textLabel?.font = font
    cell.textLabel!.text = checklist.name
    cell.textLabel?.adjustsFontSizeToFitWidth = true
    cell.textLabel?.textAlignment = NSTextAlignment.Left
    cell.accessoryType = .DetailDisclosureButton
    cell.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.5)

    cell.imageView!.image = UIImage(named: checklist.iconName)

    return cell
}

func cellForTableView(tableView: UITableView) -> UITableViewCell {
    let cellIdentifier = "Cell"
    if let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) {
        return cell
    } else {
        return UITableViewCell(style: .Subtitle, reuseIdentifier: cellIdentifier)
    }
}

这种情况下如何设置尺寸?

最佳答案

您使用 Storyboard吗?如果是这样,您可以使用自动布局并强制 imageView 的宽度和高度。您还可以通过自动布局将其附加到左侧。

还有一个不错的 cocoa pod,允许您以编程方式强制执行自动布局约束,称为 SnapKit .

关于swift - 如何更改单元格中的 ImageView 大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36865952/

相关文章:

swift - Domain=LaunchServicesError Code=0,Error=MissingBundleIdentifier,其 Info.plist 中没有 CFBundleIdentifier

swift/ cocoa : How to watch folder for changes?

swift - UICollectionView 不同大小的单元格和项目计数

ios - AutoLayout Storyboard 约束 - 如何在代码中修改以在 Orientation 更改中使用此修改

ios - Firebase、iOS 和 Swift 入门

swift - 在不同的 swift 版本中找不到 sizeForItemAtIndexPath

ios - 在IOS Realm 主键中,如何更新数据,如果已经存在,则不应花费两次?

ios - 将 Action 从 1 个 View Controller 转移到另一个

ios - UICollectionView 在自定义键盘扩展中不起作用

ios - 在 Swift 2.0 中自定义 UIButton 外观