Reputation: 93
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
Reputation: 49
For swift, add to viewDidLoad():
self.collectionView?.backgroundColor = UIColor(patternImage: UIImage(named: "background")!)
Upvotes: 4
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
Reputation: 47049
- (void)viewDidLoad
{
[super viewDidLoad];
self.collectionView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"imageName.pnd"]];
}
Upvotes: 18