2012-05-31 210 views
4

我有一個UITableViewController,我試圖定製樣式。我有95%的方法,但是無法從單元格背景中移除奇怪的陰影。我突出了什麼我想在這個屏幕截圖刪除:UITableViewCell背景顏色

Normal View

要嘗試解決這個問題,我甩了所有正在撰寫我的UITableView的意見,然後有色他們嘗試並找到我需要改變的觀點:

Styled View

正如你所看到的,我已經無法顏色的特定位置。換句話說,我找不到與該點相關的視圖。

如何從我的細胞中去除陰影?

+0

你把在那裏_something_定製的,因爲它是一個暗紅色的圖案。該模式是否爲漸變,並且漸變在每個部分中重新開始?在另一部分的頂部兩個單元的邊緣也是不正確的?你最後的結果是什麼? – jrturton

+0

@jrturton該頁面上唯一定製的是背景。我在'initWithNibName'中設置了以下代碼:'self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@「GC_TestWeight-red-background.jpg」]];' –

+0

並且該圖像是一個漸變模式,還是一致的陰影? – jrturton

回答

3

表視圖重啓每節後面的梯度,因爲它只是把你給它的顏色。

而是使用表視圖的backgroundView屬性 - 使用圖像創建圖像視圖,並將其設置爲背景視圖,或者像上面那樣創建具有背景顏色的UIView。

您需要刪除您在其他地方設置背景顏色的任何代碼,並確保您的部分標題視圖具有清晰的背景或對比背景。

作爲一個簡單的示範,我已經建立與它的背景顏色設置爲清除,並將下面的代碼分組的表視圖在表視圖控制器viewDidLoad

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    UIView *backgroundView = [[UIView alloc] initWithFrame:self.tableView.bounds]; 
    CAGradientLayer *layer = [CAGradientLayer layer]; 
    layer.colors = [NSArray arrayWithObjects:(id)[UIColor redColor].CGColor,(id)[UIColor whiteColor].CGColor, nil]; 
    layer.frame = backgroundView.frame; 
    [backgroundView.layer addSublayer:layer]; 
    self.tableView.backgroundView = backgroundView; 
} 

這給出了以下(誠然,很難看!)。細胞「漂浮」在此之上。

enter image description here

+0

@jrturon真棒。精彩地工作。非常感謝你的幫助! –