我需要將表格單元格的背景設置爲特定的顏色。 (分別爲#222222或RGB(32,32,32))表格單元格背景和文本顏色不能準確設置。
IB中表格視圖的背景設置正確。正確的灰色出現在表格標題的背面和部分標題等中。 但我與細胞鬥爭。
要定製單元格的外觀,我繼承UITableCell並實現layoutSubviews方法。
這工作得很好:
- (void)layoutSubviews {
[super layoutSubviews];
self.selectionStyle = UITableViewCellSelectionStyleGray;
self.backgroundColor = [UIColor darkGrayColor];
self.contentView.backgroundColor = [UIColor darkGrayColor];
self.textLabel.textColor = [UIColor whiteColor];
self.detailTextLabel.textColor = [UIColor grayColor];
}
然而,grayColor和darkGrayColor根本不符合我需要的顏色。
自然我嘗試了colorWithRed:green:blue:UIColor的alpha方法。
- (void)layoutSubviews {
[super layoutSubviews];
self.selectionStyle = UITableViewCellSelectionStyleGray;
self.backgroundColor = [UIColor colorWithRed:(32/256) green:(32/256) blue:(32/256) alpha:1];
self.contentView.backgroundColor = [UIColor colorWithRed:(32/256) green:(32/256) blue:(32/256) alpha:1];
self.textLabel.textColor = [UIColor whiteColor];
self.detailTextLabel.textColor = [UIColor colorWithRed:(32/256) green:(32/256) blue:(32/256) alpha:1];
}
那一個會導致detailTextLable的黑色背景和黑色。 (當然,對於背景和文本標籤,使用相同的顏色是沒有意義的,我只是試着弄清楚colorWithRed:green:blue:alpha是和不是)。
使用普通樣式表I很好。那些細胞根本沒有背景色。當我只是省略設置backgroundColor和contentView的背景顏色propierties時,單元格的背景將顯示爲IB中表格的背景顏色。 但是,對於分組表格,標準背景是一些淺灰色,我想改變爲一些更符合我客戶風格指南的體面顏色。
我在做什麼錯?我是否正確使用colorWithRed:green:blue:alpha?
任何建議,非常感謝。
'ARM處理器'中的分區由軟件完成,不提供任何硬件。因此,它更好地將數量乘以「0.003921」,而不是將其除以255以提高效率。 – Hisenberg
感謝iShery的提示。除此之外,還會解決問題。 :) –
我希望編譯將只是計算這樣的靜態數字的答案。 – rckoenes