How can I add a toolbar above the keyboard?

后端 未结 9 1334
孤街浪徒
孤街浪徒 2020-11-27 10:35

I have created a UIToolBar programmatically and added a UITextField on it. Now, I need that toolbar to be above the keyboard when I click in anothe

9条回答
  •  情歌与酒
    2020-11-27 11:23

    For swift (1.2):

    let numberToolbar = UIToolbar(frame: CGRectMake(0, 0, self.view.frame.size.width, 50))
    numberToolbar.barStyle = UIBarStyle.Default
    
    numberToolbar.items = [
        UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.Plain, target: self, action: "keyboardCancelButtonTapped:"),
        UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil),
        UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Plain, target: self, action: "keyboardDoneButtonTapped:")]
    
    numberToolbar.sizeToFit()
    yourTextView.inputAccessoryView = numberToolbar
    

提交回复
热议问题