2013-03-15 128 views
-2

我是Xcode新手,目前正在構建我的第一個應用程序。我搜索了很長時間,很難嘗試找到適當的教程,但我找不到一個。我正在尋找一種方法能夠在我的UITableViewController中插入自定義背景。我可以改變顏色,但就是這樣。我期望做的是將我的PNG圖像放置在我創建的靜態單元格後面,並將不透明度放在這些單元格上,以便自定義圖像通過。有人可以給我一個方法來做到這一點,無論是通過IB(故事板)或通過編碼。非常感激!!提前致謝!如何將自定義圖像添加到Xcode中的UITableviewController?

+0

看看這個問題,答案標記爲正確的。 http://stackoverflow.com/a/1637871/1354251列出的步驟說創建一個UIViewController,然後以編程方式在背景圖像上創建您的TableView。 – Kyle 2013-03-15 19:18:53

+0

@Kyle這是一個相當古老的問題,我認爲現在最好使用setBackgroundView方法 – guenis 2013-03-15 19:36:11

回答

2

我覺得更輕鬆,正確的方法是:

[tableView setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourimage.png"]]]; 

您可以在viewDidLoad中的代碼,使其工作。

0

細胞的背景:在willDisplayCell:atIndexPath:方法

UIImageView *cellImageView = [[UIImageView alloc] initWithImage:[UIImageimageNamed:@"image.png"]]]; 
CGRect Frame = cell.backgroundView.bounds; 
cellImageView.frame = newFrame; 

[cell.backgroundView addSubview:cellImageView]; 

的實現代碼如下背景做到這一點,爲此在viewDidLoad:方法

self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"BackgroundPattern.png"]]; 
0
UIImageView *ivwCellBackground=[[UIImageView alloc]init]; 
    [ivwCellBackground setImage:[UIImage imageNamed:CELL_BACKGROUNGIMAGE]]; 
cell.backgroundColor=[UIColor clearColor]; 

    [cell setBackgroundView:ivwCellBackground];  

    [ivwCellBackground release]; 
    ivwCellBackground=nil; 
相關問題