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没有溢出,它里面的图像溢出了。因此,您需要调整图像大小,或者使用缩放*填充模式来显示完整图像,或者根据需要对其进行裁剪
嗯