Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding a background image to a ui collection view

I am new to iOS development and I was wondering how do I add a background image that will repeat vertically to my UI Collection View that I have created to display an array of images?

like image 499
Rygarth Avatar asked Apr 03 '13 14:04

Rygarth


3 Answers

For swift, add to viewDidLoad():

    self.collectionView?.backgroundColor = UIColor(patternImage: UIImage(named: "background")!)
like image 165
Brian Glowe Avatar answered Oct 26 '22 21:10

Brian Glowe


This will work as well and I think is more correct than the work around with the background color. Go for the backgroundView directly.

- (void)viewDidLoad
{
    [super viewDidLoad];

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

}
like image 37
PakitoV Avatar answered Oct 26 '22 21:10

PakitoV


- (void)viewDidLoad
{
    [super viewDidLoad];

    self.collectionView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"imageName.pnd"]];
}
like image 44
iPatel Avatar answered Oct 26 '22 22:10

iPatel