0

I am setting a custom height and width to the UIPickerView with

  mypicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 0.0, myWidth, myHeight)];

While it works perfectly on simulator ios 10, it ignores the custom height and width on ios 8. Is there a way do this in ios 8?

I tried CGAffineTransform and it didn't work.

Many thanks in advance!

yinjia
  • 804
  • 2
  • 10
  • 20

2 Answers2

1

There are only three valid heights for UIPickerView (162.0, 180.0 and 216.0).

You can use the CGAffineTransformMakeTranslation and CGAffineTransformMakeScale functions to properly fit the picker to your convenience.

For more information this link and this link may help .

Happy to help!

Community
  • 1
  • 1
Naresh Reddy M
  • 1,096
  • 1
  • 10
  • 27
  • Thank you! I am using CGAffineTransformMakeTranslation but it makes the height of all the rows in the picker smaller as opposed to cutting the upper and lower bounds to display less numbers. If you happen to know how to cut the bounds leaving the row height the same I'd really appreciate – yinjia Sep 23 '16 at 16:37
1

The reason this doesn't work on iOS 8 is that the ability to provide your own height was not introduced until iOS 9. In iOS 8, the picker view will resist any attempts at changing its height; there is a narrow legal range of heights, and any attempt to set the height outside that range will just fail (and to add to the misery, the legal range is undocumented).

matt
  • 515,959
  • 87
  • 875
  • 1,141