2013-04-03 90 views
9

我是iOS開發新手,我在想如何添加一個背景圖像,它將垂直重複顯示圖像數組所創建的UI集合視圖?將背景圖像添加到UI集合視圖

+2

嘗試'collectionView.backgroundColor =的UIColor colorWithPatternImage:[UIImage的imageNamed:@ 「MYIMAGE」];' – jjv360

+0

請問我只是把那在View Controller的.m文件中? – Rygarth

+0

是的,在'viewDidLoad' – jjv360

回答

18
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    self.collectionView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"imageName.pnd"]]; 
} 
+0

好吧,工作!感謝jjv360和iPatel – Rygarth

32

這樣也會有效,我認爲比背景顏色更加正確。直接轉到backgroundView

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    self.collectionView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourImage.png"]]; 

} 
4

對於迅速,增加viewDidLoad中():

self.collectionView?.backgroundColor = UIColor(patternImage: UIImage(named: "background")!)