2015-05-14 248 views
0

我想改變tablecell的背景顏色。 這裏是代碼:自定義UITableViewCell背景顏色

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    var cell = tableView.dequeueReusableCellWithIdentifier("FirstMainViewTableCells") as! FirstMainViewTableCell 

    cell.backgroundColor = UIColor(red: 43, green: 65, blue: 87, alpha: 1) 

    return cell 
} 

這裏是結果:

Screenshot

但它與UIColor.blackColor()和作品的UIColor。顏色:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    var cell = tableView.dequeueReusableCellWithIdentifier("FirstMainViewTableCells") as! FirstMainViewTableCell 

    cell.backgroundColor = UIColor.blackColor() 

    return cell 
} 

Second Screenshot

你能幫助我嗎?

+2

我得到403錯誤頁面,不能查看您的保管箱。 –

+0

@ Dato'MohammadNurdin我們甚至不需要鏈接,它明顯的背景是黑色的。 – Arbitur

回答

3

顏色在iOS中介於0-1之間。您需要添加的因素得到正確的顏色代碼,請參閱下面

cell.backgroundColor = UIColor(red: 43/255.0, green: 65/255.0, blue: 87/255.0, alpha: 1); 

它應該工作。

乾杯。

+0

哦,非常感謝,我忘了它。現在它工作正常。 – dsk1306

+0

@iphonic ...正確答案。 –

相關問題