为以下方法返回自定义视图以自定义选择器行:
public override func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
return PickerAccessoryView.instantiateFromNib()
}
并返回完整宽度:
public func pickerView(_ pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat {
return pickerView.frame.width
}
不调整行视图的大小:O
答案 0 :(得分:2)
通过将自定义视图的初始帧设置为.zero来解决:
public override func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
let view = PickerAccessoryView.instantiateFromNib()
view.frame = .zero
return view
}