0

So I have UICollectionViewController and have added a UIPickerView to controllers view. Right now the UIPickerView sits beneath the nav bar.

How do I make it automatically take the bounds of the view it's within, whether on an iPhone 4 or iPhone 5 and use this to snap the UIPickerView to the bottom of it's parent.

Regards

LondonGuy
  • 10,778
  • 11
  • 79
  • 151
  • When you add the picker this way, does it scroll with the collection view? – rdelmar Apr 13 '14 at 00:07
  • @rdelmar The picker doesn't scroll with the collectionView. I added it to view instead of collectionView which is connected to my actual collection view. – LondonGuy Apr 13 '14 at 11:28

2 Answers2

1

What worked in the end was:

CGFloat viewHeight = [[self view] frame].size.height;
CGFloat pickerHeight;

UIPickerView *filterPicker = [[UIPickerView alloc] init];
pickerHeight = [filterPicker frame].size.height;
[filterPicker setFrame:CGRectMake(0, viewHeight - pickerHeight, self.view.bounds.size.width, pickerHeight)];
[[self view] addSubview:filterPicker];
LondonGuy
  • 10,778
  • 11
  • 79
  • 151
0

You will want to look into struts and springs for the picker view. This has been covered a lot on stackoverflow.

autoresizing-masks-programmatically-vs-interfact-builder-xib

Community
  • 1
  • 1
Haydon Ryan
  • 136
  • 5
  • I came across this during my search and it didn't work for me. I used filterPicker.autoresizingMask = UIViewAutoresizingFlexibleTopMargin; and it never worked for me. – LondonGuy Apr 12 '14 at 23:53
  • if you set the masks in code, are you also triggering a layout update. I read somewhere that it only works when the view gets laid out again? – Haydon Ryan Apr 13 '14 at 00:03