Question

I have a UICollectionViewController setup. It shows something kind of like a gantt chart, with selectable bars, scrolling, etc. I want to have a "trash/delete" button that always floats in the bottom right of the screen, regardless of scroll. It will delete the current selection (if there's one) in the UICollectionView.

I see two basic approaches:

  1. Use the Supplementary Views facility of my UICollectionView. What I dread about this, is that I'll have to muck with its layout in my layout (I'm using my own subclass of UICollectionViewLayout) to keep it positioned in the bottom right corner, regardless of scroll.

  2. Just add a UIButton to the canvas and set it up there. Maybe this isn't even a real approach, because this is what I wanted to do. While my button may manipulate items found in the UICollectionView, it's not really a real member of the collection view. But I found when I tried to drag a UIButton onto my Controller in the storyboard, it wouldn't stick. It doesn't seem to want to add it. Do I have to change to use a UISingleViewController, and then have a top level view that I can add both my button and collection view into? And then repeat all of the handy delegate/property setup that I get for free from UICollectionViewController?

Was it helpful?

Solution

You:

drag a button on to the view

in storyboard/xib.

Then, in the hierarchy column on the left, ensure it is at the bottom. That means it will be in front of everything else.

So, if necessary move it so it is in front of (ie, below in hierarchy) the collection view.

Note that there is absolutely no problem, at all, with putting one control "in front of" the other (i.e., so that it "blocks" you from seeing all or part of the other one).

If you had a problem doing this, you've made a trivial mistake. For example you may have dragged the new button "into" the collection view, rather than as a "sibling of" the collection view. Hope it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top