Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode 表格单元格中的UIImageView未保留在框架原始框架内?_Xcode_Swift_Uitableview_Uiimageview_Nslayoutconstraint - Fatal编程技术网

Xcode 表格单元格中的UIImageView未保留在框架原始框架内?

Xcode 表格单元格中的UIImageView未保留在框架原始框架内?,xcode,swift,uitableview,uiimageview,nslayoutconstraint,Xcode,Swift,Uitableview,Uiimageview,Nslayoutconstraint,这就是正在发生的事情: 我在图像视图中添加了一个红色背景色,这样您就可以看到它的变化程度 我试过tableView(:willDisplayHeaderView:),我试过检查子视图,我试过AspectFit,AspectFill,&ScaletoFill,但UIImageView一直超出了它们最初的界限,我不明白为什么 以下是我的UITableViewController中的一些代码: override func tableView(tableView: UITableView, c

这就是正在发生的事情:

我在图像视图中添加了一个红色背景色,这样您就可以看到它的变化程度

我试过
tableView(:willDisplayHeaderView:)
,我试过检查
子视图
,我试过
AspectFit
AspectFill
,&
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 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
}

}

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

其次,图像明显比imageView大,所以我认为imageView没有溢出,它里面的图像溢出了。因此,您需要调整图像大小,或者使用缩放*填充模式来显示完整图像,或者根据需要对其进行裁剪


HTH.

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

其次,图像明显比imageView大,所以我认为imageView没有溢出,它里面的图像溢出了。因此,您需要调整图像大小,或者使用缩放*填充模式来显示完整图像,或者根据需要对其进行裁剪