Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

Add UIToolBar to all keyboards

extension UIViewController: UITextFieldDelegate{
    func addToolBar(textField: UITextField){
        var toolBar = UIToolbar()
        toolBar.barStyle = UIBarStyle.Default
        toolBar.translucent = true
        toolBar.tintColor = UIColor(red: 76/255, green: 217/255, blue: 100/255, alpha: 1)
        var doneButton = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Done, target: self, action: "donePressed")
        var cancelButton = UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.Plain, target: self, action: "cancelPressed")
        var spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil)
        toolBar.setItems([cancelButton, spaceButton, doneButton], animated: false)
        toolBar.userInteractionEnabled = true
        toolBar.sizeToFit()

        textField.delegate = self
        textField.inputAccessoryView = toolBar
    }
    func donePressed(){
        view.endEditing(true)
    }
    func cancelPressed(){
        view.endEditing(true) // or do something
    }
}
Comment

PREVIOUS NEXT
Code Example
Swift :: swift + time delay call main thread 
Swift :: date in swiftui 
Swift :: swift 5 func to increase number every time call 
Swift :: run a function only once swift 
Swift :: swiftui navigation link with button 
Swift :: button sizetofit not working swift 
Swift :: disable dark mode swift 
Swift :: how to get the last element of an array in swift 
Swift :: swift 5 make a phone call 
Swift :: button in swiftui 
Swift :: how to get current shown collectionview cell index in swift 
Swift :: swift convert decimal to string 
Swift :: remove padding hstack swiftui 
Swift :: swift create a method who can return result or throw an error 
Swift :: change the title of a button using Swift 
Swift :: swift string concatenation 
Swift :: how to change the color of back button navbar xcodee 
Swift :: swift arrays 
Swift :: wkwebview load delegate in swift 
Swift :: navigationbarhidden not working swiftui 
Swift :: swift add two arrays 
Swift :: UIFont.init bold 
Swift :: swift extension Array where element 
Swift :: Swift guard-let Statement 
Swift :: two integer variable in swift 
Swift :: Swift Static Properties 
Swift :: Swift Weak Reference 
Swift :: procedural audio with swift 
Swift :: Swift Function overloading with Argument Label 
Swift :: how to have diffrent size images in a stack view swift 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =