私のアプリは現在このように読み込まれます。ご覧のとおり、セルがセル全体を埋めていないため、これは理想的ではありません。また、すべてのセルの一番左にあることに気が付くと、白い区切り線がセルの終わりの前で止まっています。
DayofWeekSpendingTableViewCell.xib
テーブルビュー セルをカスタマイズするためにnib ファイルを使用しています。
UITableViewController SummaryTableViewController
nibファイルをロードする場所があります。この方法tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)
では、2 つのラベルのフレームを設定して、ビューの幅を占めるようにしようとしましたが、アプリがまだこのように読み込まれるため、役に立ちません。
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 ファイルを作成する方法を誰かに教えてもらえたら、とても感謝しています!