gpt4 book ai didi

swift - UIPickerView : Toolbar is not visible on UIPickerView

转载 作者:可可西里 更新时间:2023-11-01 01:57:54 27 4
gpt4 key购买 nike

函数 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
}

enter image description here

最佳答案

你的 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()

关于swift - UIPickerView : Toolbar is not visible on UIPickerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49770582/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com