My scenario, I have created toolbarview top of the keyboard. I added UIView drag and drop on ViewController topside like below Image
Here, iPhone XI can see perfect size width, but if I run other devices width changing. so toolbarview showing half size of width, not showing perfect width. How to set auto layout and constraints for this. How to fix this?
I added view just like you
with constraints
Added this view as inputAccessoryView
myTextField.inputAccessoryView = viewAccessory
And its working fine
Edit - ToolBar as InputAccesory
You can achieve this with toolbar (w/o any constraint headache). Check below steps.
Select a toolbar like below and add this tool bar is place of your view.
Now add buttons like shown in above image by dragging and dropping UIBarButtonItem
and assign images each BarButton. To make it flexible width and equally distributed just add Flexible Space Bar Button Item
.
Now your toolbar hierarchy should be like below
And in your code
@IBOutlet var toolBarAccessory: UIToolbar!
@IBOutlet weak var myTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
myTextField.delegate = self
myTextField.inputAccessoryView = toolBarAccessory
}
Output:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.