Accessory view not attached to the keyboard on iPad - ios

I'm adding an accessory view with a "done" button on a keyboard.
I'm using this code:
let toolbar2 = UIToolbar()
toolbar2.sizeToFit()
let doneButton = UIBarButtonItem(title: "Aceptar", style: UIBarButtonItemStyle.plain, target: nil, action: #selector(donePressedPicker))
let flexibleSpace = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: self, action: nil)
toolbar2.setItems([flexibleSpace, doneButton], animated: false)
alimentosText.inputAccessoryView = toolbar2
alimentosText.inputView = picker
It works fine in the simulator with all devices. I also use it on my iPhone and works fine, but when I test it on a real iPad, the accessory view, shows exactly in the middle of the screen, not over the keyboard. How can I correct this?
This is how it looks on iPad simulator:
This is how it looks on iPhone (real device):
And this is the problem running on real iPad:
Thanks

Related

Xcode: Load native back icon as leftBarButtonItem in WKWebView

I'm using the newest version of Xcode and Swift.
I set the back button in my navigation bar as follows:
navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(goBack(_:)))
This shows the word Back in the upper left corner.
Is there a way to show the Apple native back button arrow without any text instead?
Or, do I have to load a custom back icon myself?
Use image like below.
let btnBack = UIBarButtonItem(image: UIImage(named: "Back"),
style: .plain,
target: navigationController,
action: #selector(UINavigationController.popViewController(animated:)))
navigationItem.leftBarButtonItem = btnBack
navigationController?.interactivePopGestureRecognizer?.delegate = self

How to customize UItoolbar

Twitter Registration Page
Hi everyone I have some cushions about UItoolBar on swift 3/4
I'm trying to make an singIn design like twitter,
1) i create toolbar with code;
let toolBar = UIToolbar()
toolBar.sizeToFit()
let flexibleSpace = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil)
let doneButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.done, target: self, action: #selector(self.doneClicked))
toolBar.setItems([flexibleSpace, doneButton], animated: false)
kullaniciAdi.inputAccessoryView = toolBar
eposta.inputAccessoryView = toolBar
sifre.inputAccessoryView = toolBar
but I can't add custom buttons on that. Like changing the "Done" text in my language.
2) So I created manually using Storyboard a toolBar with inside a button and Flexible Space. But ı need to "attach" that toolbar to the keyboard, so when i start to edit the textfield the toolbar will automatically show up. NOTE: it will be fantastic if the toolbar will show too when not-editing textField. Like that:
My app trying too attach toolbar
THANK YOU ALL
In Code
let sonrakiButton = UIBarButtonItem(title: "Sonraki", style: UIBarButtonItemStyle.plain, target: self, action: #selector(self.sendDoneBtnAction))
For more info, read this link

Center bar buttons in toolbar in Xcode

I have two buttons inside of a toolbar that is positioned at the bottom of the screen. I would like to center those buttons within the toolbar. Everything I have found is focused on centering buttons within a nav bar and I am unsure of how to approach this issue. What am I missing?
This is the UI I am attempting to emulate:
Adding a flexible space to the left and right of the buttons centered the buttons inside of the toolbar. Thanks to Midhun MP for the tip.
Thks #Andrew, it works
but for someone who wants it from code here is the example in Swift 5.0
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.setToolbarHidden(false, animated: true)
let spaceItemLeft = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil)
let nextItem = UIBarButtonItem(title: "NEXT", style: .plain, target: self, action: #selector(nextTapped))
let spaceItemRight = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil)
toolbarItems = [spaceItemLeft, nextItem, spaceItemRight]
}
#objc func nextTapped() {
print("NEXT Tapped")
}

adding popover to programmatically added UIBarButtonItem and adding images to the same popover Swift

From past few days i am trying to generate a popover for programmatically added UIBarButtonItem but i couldn't succeed. Added to this, i even want this popover to be presented with few images sequentially which are clickable. The following is the code of how i generated a UIBarButtonItem programmatically
func imagerendering(){
let barbuttonimage = UIImage(named: "app")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
let button1 = UIBarButtonItem(image: barbuttonimage, style: .Plain, target: self, action: nil)
self.navigationItem.leftBarButtonItem = button1
let attachButtonImage = UIImage(named: "icon-Attach")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
let attachButton = UIBarButtonItem(image: attachButtonImage, style: UIBarButtonItemStyle.Plain, target: self, action: nil)
self.navigationItem.setRightBarButtonItems([menuButton,attachButton], animated: true)
let fixedSpace:UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FixedSpace, target: nil, action: nil)
fixedSpace.width = 5.0
self.navigationItem.rightBarButtonItems = [menuButton, fixedSpace, attachButton]
self.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName:UIFont(name: "Avenir-Black", size: 16)!]
}
I have presented my desired output in an image as a link below. please go through it and let me know whether what i am desiring is possible or not.
desired output image
To add an extra bar item on navigation bar using storyboard, you can refer these answers
After that, set a popover from storyboard(you know it well as you said) and then put required buttons with actions in your popop view. You can set image for a button instead of title text.
Look into the WYPopoverController library. It gives you the functionality you're looking for.

Changing the identifier of a UIBarButton Item to an image in swift

In an iOS app I am making, I have set the identifier of a bar button item programmatically using:
homeTitleBar.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .Trash, target: self, action: nil)
Which changes the button to a trash can.
My question is, after that, how can I then change it to a custom image.
homeTitleBar.leftBarButtonItem?.image = UIImage(named: "settingsIcon")
does not seem to be working.
Try
homeTitleBar.leftBarButtonItem = UIBarButtonItem(image:UIImage(named: "settingsIcon"), style: UIBarButtonItemStyle.Plain, target: self, action: nil)

Resources