I have a toolbar for above the keyboard in an iOS swift project. When I click thorugh my app and go to certain pages before going to the one with the toolbar the done button is gone. If you click another textfield on the page it comes back until you go back to the pages of the app that mess it up. If I remove the flexible space button, it never disappears. I have checked the frame size of the toolbar and it never seems to change. The button also sometimes turns white. Not sure how this is happening if anyone has any ideas? This congifureToolbar() is called in viewdidload. I also tried calling it in viewdidappear and tried calling layoutSubviews. inputToolbar is just a UIToolbar(). I tried with custom xib toolbar, custom xib view, third party library toolbar, it never makes a difference.
func configureToolBar() {
inputToolbar.barTintColor = UIColor.groupTableViewBackground
inputToolbar.barStyle = .default
inputToolbar.isTranslucent = false
inputToolbar.sizeToFit()
inputToolbar.tintColor = UIColor(red: 0/255, green: 102/255, blue: 252/255, alpha: 1.0)
inputToolbar.setShadowImage(AppColors.shared.tableViewSeparatorColor.as1ptImage(), forToolbarPosition: .any)
let doneButton = UIBarButtonItem(title: "Done", style: .done, target: self, action: #selector(dismissKeyboard))
let flexibleSpaceButton = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
let fixedSpaceButton = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
doneButton.tintColor = UIColor(red: 0/255, green: 102/255, blue: 252/255, alpha: 1.0)
doneButton.setTitleTextAttributes([NSAttributedStringKey.foregroundColor : UIColor(red: 0/255, green: 102/255, blue: 252/255, alpha: 1.0)], for: .normal)
let nextButton = UIBarButtonItem(image: imageLiteral(resourceName: "toolbar-down"), style: .plain, target: self, action: #selector(moveToNextInput))
nextButton.tintColor = AppColors.shared.blackColor
nextButton.width = 50.0
let previousButton = UIBarButtonItem(image: imageLiteral(resourceName: "toolbar-up"), style: .plain, target: self, action: #selector(moveToPreviousInput))
previousButton.tintColor = AppColors.shared.blackColor
inputToolbar.setItems([fixedSpaceButton, previousButton, fixedSpaceButton, nextButton, fixedSpaceButton, doneButton], animated: false)
inputToolbar.isUserInteractionEnabled = true
}
If instead of a flexible space button, I put a fixed space one, I can see that the done button is getting pushed off the screen, because I can get it to be partially cut off.