函数pickerView()
在ViewLoad上调用代码
private func createPickerView(){
picker = UIPickerView(frame: CGRect(x: 0, y: 0, width: view.frame.width,height: 300))
picker.showsSelectionIndicator = true
picker.delegate = self
picker.dataSource = self
let toolBar = UIToolbar.init(frame: CGRect(x: 0, y: self.view.frame.size.height -
picker.frame.size.height-50, width: view.frame.width,height: 50))
toolBar.barStyle = UIBarStyle.default
toolBar.tintColor = UIColor(red:14.0/255, green:122.0/255, blue:254.0/255, alpha: 1)
toolBar.sizeToFit()
// TODO need to update actions for all buttons
let spaceButton = UIBarButtonItem.init(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil)
let doneButton = UIBarButtonItem.init(title: "Done", style: UIBarButtonItemStyle.done, target: self, action: #selector(self.pickerDoneAction))
toolBar.setItems([spaceButton, doneButton], animated: false)
toolBar.isUserInteractionEnabled = true
senderIdLabel.inputView = picker
senderIdLabel.inputAccessoryView = toolBar
}
答案 0 :(得分:1)
您的pickerView高度是概率,无需为工具栏设置。尝试这样工作
let picker = UIPickerView(frame: CGRect(x: 0, y: 0, width: view.frame.width,height: 215))
picker.showsSelectionIndicator = true
picker.delegate = self
picker.dataSource = self
let toolBar = UIToolbar()
toolBar.barStyle = UIBarStyle.default
toolBar.tintColor = UIColor(red:14.0/255, green:122.0/255, blue:254.0/255, alpha: 1)
toolBar.sizeToFit()