【发布时间】:2015-11-04 12:17:45
【问题描述】:
我在 Xcode 中有一个 TableViewController Swift 项目。
我制作了 3 个标签:titleLabel、deadlineLabel 和 noteLabel。
当noteLabel 为空时,如何使titleLabel 和deadlineLabel 自行调整大小并更改它们在单元格中的位置?
或者当deadLineLabel 和noteLabel 都没有出现时,如何让titleLabel 自行调整大小并更改其位置?
提前谢谢你!
以下是我的一些代码:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// let cell = tableView.dequeueReusableCellWithIdentifier("todoCell", forIndexPath: indexPath) // retrieve the prototype cell (subtitle style)
let cell = tableView.dequeueReusableCellWithIdentifier("todoCell", forIndexPath: indexPath) as! ToDoTableViewCell
let todoItem = todoItems[indexPath.row] as ToDoItem
cell.titleLabel.text = todoItem.title as String!
if (todoItem.isOverdue) { // the current time is later than the to-do item's deadline
cell.deadlineLabel.textColor = UIColor.redColor()
} else {
cell.deadlineLabel.textColor = UIColor.blueColor() // we need to reset this because a cell with red subtitle may be returned by dequeueReusableCellWithIdentifier:indexPath:
}
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "'Due' MMM dd 'at' h:mm a" // example: "Due Jan 01 at 12:00 PM"
cell.deadlineLabel.text = dateFormatter.stringFromDate(todoItem.deadline)
cell.noteLabel.text = todoItem.note as String!
【问题讨论】:
标签: ios xcode swift uitableview uilabel