日付と項目のテキストに基づいてセパレータ(UIView)の色を設定しようとしています。セクションの日付が今日の文字列の前にある場合、セパレータの色はグレーに変わり、jobDetail.textが「キャンセル」のときにセパレータの色は赤に変わります。出来ますか?Swift 3の日付とテキストに基づいてセパレータ(UIView)の色を設定します。
これはコードですが、私はすべてのセパレータの色を変更しましたが、具体的ではありません。セクションに基づいてセパレータを変更する方法は?またはセパレータを作るための他の方法?
let section = ["Mon 18 May", "Tue 19 May", "Fri 22 May"]
let items = [["Work", "Work", "Cancel"], ["Off Day"], ["Work", "Work", "Work", "mushrooms"]]
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return self.section[section]
}
func numberOfSections(in tableView: UITableView) -> Int {
return self.section.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.items [section].count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "rosterId", for: indexPath) as! RosterCell
cell.timeLabel.text = "10:00AM\n15:00PM"
cell.jobDetail?.text = self.items[indexPath.section][indexPath.row]
let today = "19 May 2017"
let headerDate = "18 May 2017"
if headerDate < today{
cell.separator.backgroundColor = UIColor(red: 1, green: 0.8314, blue: 0.1569, alpha: 1)
}else if cell.jobDetail.text == "Cancel"{
cell.separator.backgroundColor = UIColor.red
}
return cell
}
今日の日付と比較する必要がある日付形式は何ですか。 –
https://github.com/MatthewYork/DateTools – Vakas