私はXcode 6(Swift 1)でアプリを作っています。私は特定の細胞のテキストの色を緑色にしようとしていますが、他の色は赤くしていますが、うまくいきません。ここに私のコードは次のとおりです。UITableViewの特定のセルのテキストの色を変更するにはどうすればよいですか?
import Foundation
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var tableView: UITableView!
var items: [String] = ["green", "red"]
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.items.count;
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell
cell.textLabel?.text = self.items[indexPath.row]
return cell
}
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
println("You selected cell #\(indexPath.row)!")
}
}
そして、ここでは、ユニバーサルテキストの色を変更するための私のコードは次のとおりです。
cell.textLabel.textColor = [UIColor greenColor];
ので、例えば、どのように私は緑の「緑」のセル、および「赤」を作ることができますセル赤?ありがとう!
を使用すると、セルのtextLabelの色を変更している場合は? – HeavenlyManBR
"var items"宣言後 – 9fiftyfive