0

My scenario, I have created toolbarview top of the keyboard. I added UIView drag and drop on ViewController topside like below Image

enter image description here Here, iPhone X I 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?

12
  • 2
    if you could drag and drop to add it, you can also pin it in storyboard Commented Aug 1, 2019 at 5:56
  • how to do that? Sorry I can't get you @Lu_ Commented Aug 1, 2019 at 5:57
  • Show us the constraints you applied to Tool Bar in Interface Builder Commented Aug 1, 2019 at 5:59
  • did you use storyboard ever before? you can search stack overflow for storyboard constraints Commented Aug 1, 2019 at 6:00
  • 1
    you didn't show any code, there is no screenshots from visual debugger, it is hard to understand question like that Commented Aug 1, 2019 at 6:05

1 Answer 1

2

I added view just like you

enter image description here

with constraints

enter image description here

Added this view as inputAccessoryView

myTextField.inputAccessoryView = viewAccessory

And its working fine

enter image description here


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.

enter image description here

enter image description here

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.

enter image description here

Now your toolbar hierarchy should be like below

enter image description here

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:

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

wow. this is I am expected. I have same like this but not working anyway I am dong double check, I will add my constraint screen. thanks man
please check above updated my question. still its not working. Please let me know if I did anything mistakes.
@BenDev Check updated answer. You dont need any single constraint. If you wanted to try new update then go with it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.