Reputation: 276
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?
Upvotes: 3
Views: 3634
Reputation: 191
I think you need to remove the two lines of the selected row, if so then you can use the titleForRow or viewForRow delegate method of pickerView and use the following code in the delegate method.
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
[[pickerView.subviews objectAtIndex:1] setHidden:TRUE];
[[pickerView.subviews objectAtIndex:2] setHidden:TRUE];
}
OR
- (UIView *)pickerView:(UIPickerView *)pickerView
viewForRow:(NSInteger)row
forComponent:(NSInteger)component
reusingView:(UIView *)view
{
[[pickerView.subviews objectAtIndex:1] setHidden:TRUE];
[[pickerView.subviews objectAtIndex:2] setHidden:TRUE];
}
Upvotes: -1
Reputation: 12218
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
}
}
}
Upvotes: 6
Reputation: 528
in picker view datasource method
func numberOfComponents(in pickerView: UIPickerView) -> Int {
pickerView.subviews.forEach({
$0.isHidden = $0.frame.height < 1.0
})
return 1
}
the lines will be gone
Upvotes: 4