Search code examples
iosuipickerviewtoolbarswift3

Unable set inputAccessoryView toolbar in Pickerview


in swift 3, i am unable set toolbar in pickerview like

pickerFilter?.inputAccessoryView = barAccessory

error is that inputAccessoryView is get-only property.

and When i am addsubview in Pickerview. toolbar is shown but done button not clickable

any solution?


Solution

  • let flexiblespace = UIBarButtonItem(barButtonSystemItem:.flexibleSpace , target: nil, action: nil)
    
        let btnDone = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(self.donePresed))
        let barAccessory = UIToolbar(frame: CGRect(x: 0, y: 0, width: viewPicker.frame.size.width, height: 44))
        barAccessory.barStyle = .default
        barAccessory.isTranslucent = true
        barAccessory.items = [flexiblespace,btnDone]
    
        viewPicker.addSubview(pickerDrpDown!)
        viewPicker.addSubview(barAccessory)