默认的“UIPickerView”在我想删除的顶部和底部有一条细灰线,但我找不到如何做到这一点。
我可以设置某个属性来清除吗?
答案 0 :(得分:5)
在选择器视图数据源方法
中 func numberOfComponents(in pickerView: UIPickerView) -> Int {
pickerView.subviews.forEach({
$0.isHidden = $0.frame.height < 1.0
})
return 1
}
线条将消失
答案 1 :(得分:4)
你必须继承UIPickerView
,因此:
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
}
}
}
答案 2 :(得分:-1)
我认为您需要删除所选行的两行,如果是这样,那么您可以使用pickerView的titleForRow或viewForRow委托方法,并在委托方法中使用以下代码。
- (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];
}