我的应用程序当前加载是这样的。如您所见,这不是理想的 b/c 单元格不会填满整个单元格。此外,如果您注意到每个单元格的最左侧,白色分隔线会在单元格末尾之前停止。
我正在使用 nib 文件DayofWeekSpendingTableViewCell.xib
来自定义我的 tableview 单元格。
我有一个UITableViewController SummaryTableViewController
加载 nib 文件的位置。在该方法tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)
中,我尝试设置两个标签的框架,以便它们占据视图的宽度,但这无济于事,因为我的应用程序仍然像这样加载。
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 文件以适应视图,我将不胜感激!