Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add a toolbar above the keyboard?

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 another text field.

UIToolbar *toolBar=[[UIToolbar alloc]initWithFrame:CGRectMake(0,400, 320, 60)]; [self.view addSubview:toolBar];  UITextField *txtView=[[UITextField alloc]initWithFrame:CGRectMake(0, 400, 260, 30)]; txtView.backgroundColor =[UIColor  grayColor]; txtView.placeholder=@"Address"; UIBarButtonItem *txtfieldItem=[[UIBarButtonItem alloc]initWithCustomView:txtView]; toolBar.items =[NSArray arrayWithObject:txtfieldItem]; 
like image 397
Sushil Sharma Avatar asked May 28 '14 07:05

Sushil Sharma


People also ask

What is Inputaccessoryview?

A component which enables customization of the keyboard input accessory view on iOS. The input accessory view is displayed above the keyboard whenever a TextInput has focus. This component can be used to create custom toolbars.

How do I change the toolbar on my keyboard?

If the toolbar is currently below the ribbon, press the Down arrow key repeatedly until you reach the first item on the Quick Access Toolbar, then press the Right arrow key until you reach the Customize Quick Access Toolbar button. To expand the menu, press Alt+Down arrow key.

How to add a keyboard to taskbar in Windows 10?

Method 2: Add the keyboard to taskbar in Taskbar and Start Menu Properties. Step 1: Open the Taskbar and Start Menu Properties window. Right-tap any blank space on the taskbar and choose Properties. Step 2: Make changes to Toolbars settings. Open Toolbars, check the box before Touch Keyboard and tap OK.

How do I add a button to the toolbar?

To add the button to the toolbar, press A. Add buttons for features that aren't on the ribbon In any Office app, press the Alt key. Press the Up arrow key once to move to the Quick Access Toolbar.

How do I use the Quick Access toolbar on my keyboard?

Use the buttons on the Quick Access Toolbar To access and use the buttons on the Quick Access Toolbar while editing a document in any Office app, press the Alt key and then press the Key Tip number associated with the feature. If you're using a screen reader and the Quick Access Toolbar is above the ribbon, press the Alt key.


1 Answers

UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 50)]; numberToolbar.barStyle = UIBarStyleBlackTranslucent; numberToolbar.items = [NSArray arrayWithObjects:                                [[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelNumberPad)],                                [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],                                [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)],                                nil]; [numberToolbar sizeToFit]; phonenumberTextField.inputAccessoryView = numberToolbar; 

To Dismiss Keyboard:

[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil]; 

Swift 3:

let numberToolbar = UIToolbar(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, 50)) numberToolbar.barStyle = UIBarStyle.Default numberToolbar.items = [             UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.Plain, target: self, action: "cancelNumberPad"),             UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil),             UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Plain, target: self, action: "doneWithNumberPad")]     numberToolbar.sizeToFit()     phonenumberTextField.inputAccessoryView = numberToolbar 

Swift 4.2:

let numberToolbar = UIToolbar(frame:CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50)) numberToolbar.barStyle = .default numberToolbar.items = [ UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(cancelNumberPad)), UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil), UIBarButtonItem(title: "Done", style: .plain, target: self, action: #selector(doneWithNumberPad))] numberToolbar.sizeToFit() phonenumberTextField.inputAccessoryView = numberToolbar  ...  @objc func cancelNumberPad() {     //Cancel with number pad } @objc func doneWithNumberPad() {     //Done with number pad } 
like image 165
Kittu Avatar answered Oct 03 '22 12:10

Kittu