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:52

This is easily achieved. Just place your PickerView inside a ScrollView with the desired size of your row, and use the picker delegate(pickerView:rowHeightForComponent:) method to change the the row height of the picker to a little bigger than your ScrollView. Like that, the lines will be hidden.

查看更多
ら.Afraid
3楼-- · 2019-01-17 03:53

I solved this by a simple trick: Place picker view in a view, and set clip subviews property of this view = true. Now, just set height of row in picker view = height of container view then the line will disappear.

查看更多
爷的心禁止访问
4楼-- · 2019-01-17 03:54

I opted for a different approach to make it a bit more future proof just in case Apple decide to change something down the line

for subview in setPickerView.subviews{
    if subview.frame.origin.y != 0{
        subview.isHidden = true
    }
}

since the (subView that contains the items)'s origin y location is 0 then I can safely hide anything else without risking an index out of bounds error

Enjoy

EDIT: I forgot to tell you that I put it in the viewDidLayoutSubviews method!

查看更多
登录 后发表回答