[英]UITableView Background Color Swift
我想使用Swift更改UITableView背景的顏色。 我想使單元格背景以及實際表格的背景都具有特定的顏色。 到目前為止,我已經使用以下代碼創建了一個簡單的表:
import UIKit
class MyTripsViewController: UIViewController, UITableViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cell")
cell.textLabel?.text = "Test"
return cell
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
單元格屬性backgroundColor
更改背景色。 設置顏色:
cell.backgroundColor = UIColor(red: 0.1, green: 0.2, blue: 0.3, alpha: 1.5)
或使用預定義的顏色:
cell.backgroundColor = UIColor.blueColor()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.