kishor0011 kishor0011 - 1 year ago 94
Swift Question

How can we add a button over collection view using swift?

I have a

in my

I want to add a circle button to redirect to new page, But in
is it possible to drag a button over
? I don't know about footer how can we achieve.

It should looks like
is scrolling and button will be over the collection view, I mean no effect on button.

Answer Source

Yes you can do it,

If using UIViewController Put your button above collectionview like this,

enter image description here

If using UICollectionViewContoller, you can't add button to storyboard, you need to add button programmatically. Call below function in viewDidLoad().

fileprivate func addButton(){
        let button = UIButton()
        button.setTitle("Button", for: UIControlState.normal)
        button.setTitleColor(, for: UIControlState.normal)
        button.frame = CGRect(x: 0, y: 0, width: 100, height: 50) = CGPoint(x: (collectionView?.frame.width)!/2, y: (collectionView?.frame.height)!-30)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download