2011-09-22 194 views

回答

2

您可以更改單元格的顏色在UITableView的委託方法是這樣的:

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

    UITableViewCell *cell = [tableView 
       dequeueReusableCellWithIdentifier:@"UITableViewCell"]; 

    if (!cell) {   
     cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle 
             reuseIdentifier:@"UITableViewCell"]autorelease]; 
    } 
} 

//在這裏你可以去與任何顏色/你的背景改成你想要

//改變顏色:

[cell setBackgroundColor:[UIColor blackColor]]; 

//改變的細胞的背景圖像:

UIImage *theImage = [UIImage imageNamed:@"ximage.png"]; 
    [[cell imageView] setImage:theImage]; 

}

+0

謝謝,但我將如何改變導航欄的顏色?我沒有將它添加到Interface Builder中;它是以編程方式創建的。 –

+0

UINavigationController * myNavController; myNavController.navigationBar.tintColor = [UIColor redColor]; – 2011-09-22 01:33:27

+0

正是我在找的東西。我只是把它放在我的應用程序delegate.m中,它工作得很完美。謝謝! –

0

要更改單元格的顏色,您需要創建自己的UITableViewCell的子類。而要改變導航欄的背景顏色,我相信這是

self.navigationItem.backgroundColor = [UIColor redColor]; 

感謝,

macintosh264

0

您可以通過backgroundView設置表和a的內容查看的的backgroundColor這樣做細胞。請參閱this以開始使用。導航欄可以通過繼承UINavigationBar並重寫drawRect方法來完成。

P.S:以上所有內容都是基本主題,教程遍佈整個Web和Stack Overflow本身。嘗試搜索並閱讀。

0

注意,從IOS3你不設置單元格背景顏色

  • (UITableViewCell的*)的tableView:(UITableView的*)的tableView 的cellForRowAtIndexPath:(NSIndexPath *)indexPath

將其設置在

  • (無效)tableVie女:(UITableView的*)的tableView willDisplayCell:(的UITableViewCell *)細胞forRowAtIndexPath:(NSIndexPath *)indexPath

這裏指出

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html