2012-02-02 44 views
0

設置顏色表中我知道如何設置顏色爲純表。 如果切換到組合表格,背景顏色也會移動並位於表格本身之外的背景中。 也可以設置顏色到表格。即一種顏色用於外部區域,另一種用於桌面?是否有可能在分組表

+0

看看這個以前SO質疑http://stackoverflow.com/questions/400965/how-to-customize-the-background-border-colors-of-a-grouped-table-view – visakh7 2012-02-02 08:17:56

回答

1

這可以通過添加幾行代碼來完成。

對於使用圖像作爲背景,

tableView.opaque = NO; 
[tableView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"image.png"]]]; 

對於使用單一顏色,您可以使用,

tableView.opaque = NO; 
    [tableView setBackgroundColor:[UIColor blueColor]]; 

更多詳細信息,你可以看一下this tutorial

+0

真是太爽了,謝謝。 – 2012-02-02 09:35:38

+0

將圖片設置爲背景時,就像兩張圖片。一個就像一個完整的背景,相同的圖像就像我的分組桌子周圍的框架,跟隨着scoll,但另一個背景是固定的。結果是帶有圖片的框架在相同的圖片背景下滑動,看起來有點奇怪。如果框架不在那裏,那將是完美的。你碰巧知道如何解決這個問題? – 2012-02-03 12:18:23

1

對於使用

[myTableView setBackgroundColor: [UIColor redColor]]; 

和內彩,可以設置將電池在UITableView的數據源的方法的背景顏色外的顏色可以通過界面生成器或通過代碼設置表背景色:

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString * CellIdentifier = @"customCell"; 
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
} 

cell.backgroundColor = [UIColor greenColor]; 

return cell; 

} 
+0

謝謝,效果很好! – 2012-02-02 09:35:14

+0

謝謝!如果您投票回答我的答案並將其選爲接受答案,我將不勝感激。這將有助於我們建立聲譽。 – 2012-02-02 10:14:06

+0

現在我將你的答案標記爲一個有用的答案。你是這個意思嗎?? – 2012-02-02 11:48:51