在pickerView的委托方法中更改线视图的高度:
public func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
for view in pickerView.subviews {
if view.frame.size.height < 1 {
var frame = view.frame
frame.size.height = 2
view.frame = frame
view.backgroundColor = UIColor.black
}
}
let label = UILabel()
label.text = "Test Text" //remember to change it to the real data
label.textAlignment = NSTextAlignment.center
return label
}
记得设置PickerView的委托:
self.pickerView.delegate = self //or do this in XIB or Storyboard.