###前提・実現したいこと
以下のようにカスタムセル内にViewとLabelを追加しています。
●(view) タイトル(label)
○ タイトル
このようなカスタムセルにおいて、viewの背景色を配列に応じて変更したい。
###試したソースコード
swift
1//データを用意 2let Lists = ["ProjectA","ProjectB","ProjectC"] 3let Colors = ["red","green","orange"] 4 5//ここで色を変更しようとしています 6func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 7 let cell = tableView.dequeueReusableCell(withIdentifier: "TestCell") as! TodoContentSelectTableViewCell 8 cell.testTitle.text = Lists[indexPath.row] 9 cell.testColor.backgroundColor = UIColor.Colors[indexPath.row] 10 return cell 11 } 12 13func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 14 return Lists.count 15 }
@IBOutlet、delegete等は設定済みです。
このように、データに保存された内容によって、背景色を変更する場合どのように実装すればよいのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/05/03 11:25