簡體   English   中英

所有單元格的UITableViewCell BackgroundImage

[英]UITableViewCell BackgroundImage for ALL Cells

我將所有UITableViewCell的背景圖像設置為以下代碼中的相同模式:

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"SelectAnAlbumTableViewCellBackground"]] autorelease];
}

哪個有效,除了任何空單元格。 我想知道如何設置ALL UITableViewCell的背景,而不僅僅是那些有數據的背景?

問題是方法
`

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

僅針對非空單元格調用。

因此,您可以增加此方法中的單元格數

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

當你在數據庫中添加數據時,你會添加標簽或你想要的東西,但當你在空單元格中時,你什么都不做。

為tableview設置該單元格圖像。

  TableView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"Cellimage.png"]];

這是我的手機圖像:

在此輸入圖像描述

這是我的桌面視圖:

在此輸入圖像描述

如果您需要為Cell設置背景圖像,只需使用以下行:

UIImageView *myImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellImage.png"]];
myImgView.frame = CGRectMake(0, 0, 300, 50);
[cell.contentView addSubview:myImgView];

通過使用此代碼,您將獲得它獲取數據原因的圖像,因為它獲取數據時只有調用。

如果要這樣做,則必須設置表格背景顏色。

希望這會有所幫助。

暫無
暫無

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

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