IOS7 UIPickerView how to hide the selection indica

2019-01-17 02:58发布

How can I hide those 2 lines on the selected row?

enter image description here

15条回答
狗以群分
2楼-- · 2019-01-17 03:31
[[pickerview.subviews objectAtIndex:1] setHidden:TRUE];
[[pickerview.subviews objectAtIndex:2] setHidden:TRUE];

Use this in titleForRow or viewForRow delegate method of the pickerView.

查看更多
倾城 Initia
3楼-- · 2019-01-17 03:31

Just write this code in your viewdidload method

[[PickerView.subviews objectAtIndex:1] setHidden:TRUE];
[[PickerView.subviews objectAtIndex:2] setHidden:TRUE];
查看更多
Root(大扎)
4楼-- · 2019-01-17 03:32

It is working before ios7.

pickerView.showsSelectionIndicator = NO;

for more info in ios7 see this doc

https://developer.apple.com/library/ios/documentation/userexperience/conceptual/UIKitUICatalog/UIPickerView.html

查看更多
唯我独甜
5楼-- · 2019-01-17 03:32

In ios7 we can't hidden the separate line in UIPickerView and we can know that from this page: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIPickerView_Class/index.html#//apple_ref/occ/instm/UIPickerView/showsSelectionIndicator

But we can add two UIViews to cover it and the width of two UIViews is 1. Some sample code here:

s_leftLine = [[UIView alloc] initWithFrame:CGRectMake(s_pickerView.frame.size.height/2,
                                                      s_pickerView.frame.size.width/2 - kWidthOfPickerPage/2 + 1,
                                                      1,
                                                      s_pickerView.frame.size.height)];
s_leftLine.backgroundColor = [UIColor whiteColor];
s_leftLine.layer.zPosition = s_pickerView.layer.zPosition + 1; // make sure the line is on the top
[s_pickerView addSubview:s_leftLine];

Ok, this will be much better :] if someone has better answer just write it down for sharing :)

查看更多
你好瞎i
6楼-- · 2019-01-17 03:36

In iOS7 setting the parameter pickerview.showsSelectionIndicator has no effect, according to the documentation (https://developer.apple.com/library/ios/documentation/userexperience/conceptual/UIKitUICatalog/UIPickerView.html).

However, as a UIPickerView in the end is a UIView with subviews, I checked what subviews there were. I found 3, the first one contained all the components of the UIPickerView, and the other two are the two lines.

So by setting the second and third (index 1 and 2) hidden, the two lines were removed.

[[pickerview.subviews objectAtIndex:1] setHidden:TRUE];
[[pickerview.subviews objectAtIndex:2] setHidden:TRUE];

It's not a real nice solution, and definitely not forward compatible, but for now it gets the job done. Hope this helps.

查看更多
霸刀☆藐视天下
7楼-- · 2019-01-17 03:36

This worked for me in Swift in iOS 9 Beta.

datePicker.subviews[0].subviews[1].hidden = true
datePicker.subviews[0].subviews[2].hidden = true
查看更多
登录 后发表回答