Reputation: 97
I'm desperately trying to place a UIButton on top of my UICollectionView. The goal is something like the check-in button from the new foursquare app.
My code currently looks like so:
UIButton *floatingButton = [[UIButton alloc] init];
[floatingButton setFrame:CGRectMake(320, 150, 50, 50)];
[floatingButton setBackgroundColor:[UIColor blackColor]];
[self.collectionView addSubview:floatingButton];
[self.collectionView bringSubviewToFront:floatingButton];
The problem is the button isn't anywhere.
Upvotes: 3
Views: 2640
Reputation: 31
I had the same problem. Add your button to collectionView superView, might be self.view.
[self.view addSubview:floatingButton];
and set the button as firstResponder.
[floatingButton becomeFirstResponder];
Upvotes: 2
Reputation: 1549
you probably want to add the button to the collectionView's parent view. most likely self.view, but its hard to say for sure without seeing more code.
instead of
[self.collectionView addSubview:floatingButton];
you probably want
[self.view addSubview:floatingButton];
Upvotes: 3