Swift 3 PickerView
文本框üzerinebasılıncaaçılanpickerview ileseçiminizikolaylıklayapabileceğinizbirörnek。 显示文本框,以显示德语。 Kodlarıbiraz incelerseniz kendinizegöreçokkolay birşekildedeğişiklikleryapabileceğinizigöreceksiniz。 Yararlıolmasıdileğiyle🙂
导入UIKit类ViewController:UIViewController,UIPickerViewDelegate,UIPickerViewDataSource,UITextFieldDelegate {@IBOutlet弱var txt_pickUpData:UITextField!var myPickerView:UIPickerView!var pickerData = [“ Yakup”,“ Swift 3”,“ Apple”,“ Macbook”,“ IPhone”, “ Xcode”]覆盖func viewDidLoad(){super.viewDidLoad()} func pickUp(_ textField:UITextField){// UIPickerViewself.myPickerView = UIPickerView(frame:CGRect(x:0,y:0,width:self.view) .frame.size.width,height:216))self.myPickerView.delegate = selfself.myPickerView.dataSource = selfself.myPickerView.backgroundColor = UIColor.whitetextField.inputView = self.myPickerView //工具栏工具栏= UIToolbar()toolBar.barStyle = .defaulttoolBar.isTranslucent = truetoolBar.tintColor = UIColor(红色:92/255,绿色:216/255,蓝色:255/255,alpha:1)toolBar.sizeToFit()//添加按钮ToolBarlet doneButton = UIBarButtonItem(title: “完成”,样式:.plain,目标:自我,操作:#selector(ViewController.doneClick))let spaceButton = U IBarButtonItem(barButtonSystemItem:.flexibleSpace,目标:无,动作:无)let cancelButton = UIBarButtonItem(标题:“取消”,样式:.plain,目标:自我,动作:#selector(ViewController.cancelClick))toolBar.setItems([ cancelButton,spaceButton,doneButton],动画:false)toolBar.isUserInteractionEnabled = truetextField.inputAccessoryView = toolBar} // MARK:-PickerView委托和DataSourcefunc numberOfComponents(在pickerView中:UIPickerView)-> Int {返回1} func pickerView(_ pickerView: UIPickerView,numberOfRowsInComponent组件:Int)-> Int {返回pickerData.count} func pickerView(_ pickerView:UIPickerView,titleForRow行:Int,forComponent组件:Int)->字符串? {return pickerData [row]} func pickerView(_ pickerView:UIPickerView,didSelectRow row:Int,inComponent component:Int){self.txt_pickUpData.text = pickerData [row]} // MARK:-TextFiled Delegatefunc textFieldDidBeginEditing(_ textField:UITextField ){self.pickUp(txt_pickUpData)} // MARK:Buttonfunc doneClick(){txt_pickUpData.resignFirstResponder()} func cancelClick(){txt_pickUpData.resignFirstResponder()}覆盖func didReceiveMemoryWarning(){super.didReceive / MemoryDiscover()可以重新创建的任何资源。}}
Kaynak https://github.com/kiritmodi2702/PickerView-Swift3.0/blob/master/FixImageOrientation/ViewController.swift