簡體   English   中英

設置UITableViewCell和UITableView背景的顏色

[英]Setting colors of UITableViewCell and UITableView background

我試圖為TableView使用背景圖片,所以當沒有足夠的數據填充屏幕上的整個表格時,我不會得到剩余的tableview單元格,因此我嘗試使用此URL,但更為簡單: http: //cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html

我在有UITableView出口的viewcontroller中執行此操作:

    UIImage *backgroundTableImage = [UIImage imageNamed:@"form_background.png"]; // basically a gray->white gradient
    UIImageView *tableBackgroundImageView = [[UIImageView alloc] initWithImage:backgroundTableImage];
    tableBackgroundImageView.frame = self.TableView.bounds;
    self.TableView.backgroundView = tableBackgroundImageView;
    [tableBackgroundImageView release];
    self.backgroundColor = [UIColor clearColor];

然后,我有一個在IB中創建的UITableViewCell的自定義子類。 在IB中,其背景設置為White-default。 我的單元格都是透明的,並且只看到背景。 如何使細胞保持白皙。

首先,在您的.h文件中查看UIView * newView; 聲明其屬性並在您的.m文件中對其進行合成

現在在cellForRowAtIndexPath中

if(cell==nil){

        tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"imagename.png"]];

................
.........
newView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height)];
[cell.contentView addSubview:newView];
................
...............
}
if(indexPath.row == 0){

newView.backgroundColor = [UIColor blueColor];

}
if(indexPath.row == 1){

newView.backgroundColor = [UIColor redColor];

}
if(indexPath.row == 2){

newView.backgroundColor = [UIColor greenColor];

}

如有其他問題,請敲我。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM