AdorableMelon
AdorableMelon

Reputation: 15

Add border to CollectionView

I have a collection view with multiple cells in it, I figured out how to add a border to each cell but still stuck with adding a border to the CollectionView (expected Result).

Currently, I'm placing the button outside the CollectionView but don't know how to make it looks like the expected result.

Current view

Expected Result

Upvotes: 0

Views: 984

Answers (2)

Faysal Ahmed
Faysal Ahmed

Reputation: 7669

For set the collection view border you can follow this

collectionView.layer.borderColor = UIColor.gray.cgColor  
collectionView.layer.borderWidth = 5  

And for setting cell position to the middle you need to set the cell insect. You can easily set the cell insect from storyboard from this. Update the Section Insects value that you want.

enter image description here

Upvotes: 1

Santosh Kumar J M
Santosh Kumar J M

Reputation: 181

you can try like this:

@IBOutlet var CollectionView: UICollectionView!

 override func viewDidLoad() {
 super.viewDidLoad()

CollectionView.delegate = self
CollectionView.dataSource = self

CollectionView.layer.borderColor = UIColor.gray.cgColor //change to required color
CollectionView.layer.borderWidth = 5 //change to required borderwidth
}

Upvotes: 0

Related Questions