Search code examples
iosswiftuipickerview

Remove UIPickerView Borders


The default "UIPickerView" has a thin gray line at the top and bottom that I want to remove, but I can't find out how to do that.

Is there a property somewhere that I can set to clear?


Solution

  • You have to subclass UIPickerView, as such:

    class MyPickerView: UIPickerView {
    
        override func layoutSubviews() {
            super.layoutSubviews()
    
            self.layer.borderWidth = 0 // Main view rounded border
    
            // Component borders
            self.subviews.forEach {
                $0.layer.borderWidth = 0
                $0.isHidden = $0.frame.height <= 1.0
            }
        }
    
    }