Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add background image for collectionview

Do anyone have idea to add the background image to the collectionview directly in storyboard and is it possible to do so?

like image 290
meowsush Avatar asked Feb 02 '17 10:02

meowsush


2 Answers

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

like image 118
Edu Avatar answered Sep 29 '22 09:09

Edu


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

like image 27
Devang Tandel Avatar answered Sep 29 '22 09:09

Devang Tandel