【发布时间】:2016-01-08 03:51:31
【问题描述】:
我的应用当前加载类似于this。如您所见,这不是理想的 b/c 单元格不会填满整个单元格。此外,如果您注意到每个单元格的最左侧,白色分隔线会在单元格末尾之前停止。
我正在使用 nib 文件 DayofWeekSpendingTableViewCell.xib 来自定义我的 tableview 单元格。
我有一个UITableViewController SummaryTableViewController,我在其中加载 nib 文件。在 tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) 方法中,我尝试设置两个标签的框架,以便它们占用视图的宽度,但这无济于事,因为我的应用程序仍然像 this. 那样加载
class SummaryTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
dayOfWeek = [ .Mon, .Tue, .Wed, .Thu, .Fri, .Sat, .Sun]
totalSpentPerDay = [0, 7.27, 0, 0, 39, 0, 0]
// Create a nib for reusing
let nib = UINib(nibName: "DayofWeekSpendingTableViewCell", bundle: nil)
tableView.registerNib(nib, forCellReuseIdentifier: "nibCell")
self.tableView.separatorColor = UIColor.whiteColor()
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// Configure the cell...
let cell = tableView.dequeueReusableCellWithIdentifier("nibCell", forIndexPath: indexPath) as! DayOfWeekTableViewCell
let day = dayOfWeek[indexPath.row]
let height = CGFloat(55)
let dayOfWeekWidth = CGFloat(80)
cell.dayOfWeek.text = day.rawValue.uppercaseString
cell.dayOfWeek.frame = CGRectMake(0, 0, dayOfWeekWidth, height)
cell.dayOfWeek.backgroundColor = colorOfDay[day]
cell.totalAmountSpent.text = "$\(totalSpentPerDay[indexPath.row])"
cell.totalAmountSpent.frame = CGRectMake(cell.dayOfWeek.frame.maxX + 1, 0, view.bounds.width - dayOfWeekWidth, height)
cell.totalAmountSpent.backgroundColor = colorOfDay[day]
return cell
}
}
如果有人能告诉我如何制作自定义 UITableViewCell nib 文件以适应视图,我将不胜感激!
【问题讨论】:
-
您尝试过使用自动布局吗?
-
你想要的结果是什么?
-
我遇到了同样的问题,我解决了将布局约束放在我的 nib 文件中的自定义单元格
标签: ios swift uitableview uinib