UIPickerView with custom views broken in iOS7
Asked Answered
B

4

12

I have an app with a UIPickerView. I am returning a custom view with the method

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view 

It looked fine in iOS 6. In iOS 7, not so much -- screen shot below.

Notice that in the cells that don't have focus, the second and third columns overlap. The central row is correct.

Any suggestions?

enter image description here

Bondwoman answered 30/10, 2013 at 2:53 Comment(1)
That is strange. I have created one for test it. But everything is ok. Example snipt.org/BaIi0/Default.Whimsical
C
9

It seems that for a strange reason, if the width of any column is higher than 1/3 of the picker view's width the layout breaks. So if you have a 320 pixel wide picker view 106 or less is working, but 107 or higher is wrong, regardless if you have 2,3,4 ... components. Really strange.

Capeskin answered 2/11, 2013 at 15:47 Comment(2)
The only workaround I see so far is to increase the width of the first component, and decrease the width of the others on iOS 7.Capeskin
Thanks! Still happens nowadays.Dereliction
H
3

As imihaly said in his earlier post it looks like this only happens if the widthForComponent value for the LAST component is more than 106 pixels. The other components can return a value over 106 and it will look fine. Also, if you return a view that's smaller in width than the value returned by widthForComponent it will center the view, but it will be offset to the left by about 10 pixels.

Handbreadth answered 4/11, 2013 at 22:24 Comment(0)
P
0

I had a similar issue, but I was displaying simple numbers instead. See my similar question. Short answer is that I had to break up the components into different UIPickerViews.

Proconsul answered 7/11, 2013 at 2:9 Comment(0)
R
0

As @imihaly mentioned, There is only one solutions that I come up with to increase a width of picker view which is add into view.

I have created a demo like https://github.com/Dharmesh-shah2412/demoPickerView

Rees answered 9/2, 2018 at 13:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.