Rygarth
Rygarth

Reputation: 93

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?

Upvotes: 9

Views: 11987

Answers (3)

Brian Glowe
Brian Glowe

Reputation: 49

For swift, add to viewDidLoad():

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

Upvotes: 4

PakitoV
PakitoV

Reputation: 2498

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"]];

}

Upvotes: 34

iPatel
iPatel

Reputation: 47049

- (void)viewDidLoad
{
    [super viewDidLoad];

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

Upvotes: 18

Related Questions