Reputation: 197
Do anyone have idea to add the background image to the collectionview directly in storyboard and is it possible to do so?
Upvotes: 11
Views: 8493
Reputation: 930
This will work perfectly than the background color.
- (void)viewDidLoad
{
[super viewDidLoad];
self.collectionView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"imageName"]];
}
Upvotes: 4
Reputation: 402
Better to do it programmatically creating a imageView like this
let imageView : UIImageView = {
let iv = UIImageView()
iv.image = UIImage(named:"imagename")
iv.contentMode = .scaleAspectFill
return iv
}()
and on the ViewDidLoad method
self.collectionView?.backgroundView = imageView
That'll make the background the image that you want
Upvotes: 12
Reputation: 3008
Yes it is possible I am using xcode 8.1 and it is possible in this version of xcode, I am not sure of other. for XCode 8.1 i have tried and working as expected.
you just have to drag UIImageView on UICollectionView and its done. Even it will automatically resize your UIImageView according to the size of your UICollectionView
Upvotes: 12