table 单元格中的 UIImageView 没有停留在框架原始框架内?

UIImageView in table cell is not staying within frame original frame?

这就是正在发生的事情:

我已经在图像视图中添加了红色背景颜色,这样您就可以看到它已经超过了多少。

我试过 tableView(:willDisplayHeaderView:),我试过勾选 Subviews,我试过 AspectFitAspectFill,& ScaletoFill 但是UIImageView 不断超出其原始边界,我不明白为什么。

这是我 UITableViewController:

的一些代码
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("scheduleCell", forIndexPath: indexPath) as! ScheduleTableViewCell
    let eventList = schedule?.schedule[dayOfWeek[indexPath.section]]!
    let event = eventList![indexPath.row]
    cell.labelEvent.text = event.act.rawValue
    cell.labelTime.text = "\(event.getTime(event.start)) - \(event.getTime(event.end))"

    return cell
}

    override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
    let tableViewCell = cell as! ScheduleTableViewCell
    let eventList = schedule?.schedule[dayOfWeek[indexPath.section]]!
    let event = eventList![indexPath.row]
    tableViewCell.imageView?.image = UIImage(named: "\(schedule!.potato.mode)-\(event.act.rawValue)")
    tableViewCell.imageView?.backgroundColor = UIColor.redColor()
    tableViewCell.imageView?.contentMode = .ScaleAspectFit

}

这是我的自定义单元格 class:

class ScheduleTableViewCell: UITableViewCell {

@IBOutlet weak var imageEvent: UIImageView!
@IBOutlet weak var labelEvent: UILabel!
@IBOutlet weak var labelTime: UILabel!

override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
}

override func setSelected(selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

    // Configure the view for the selected state
}

}

首先,将 imageViewclipsToBounds 属性 设置为 true 将防止图像溢出 imageView 的边界。

其次,image明显比imageView大,所以我觉得不是imageView溢出,是里面的image溢出。因此,您需要调整图像大小或使用缩放*填充模式来显示完整图像或适当裁剪它。

HTH.