Reputation: 57
Everything is fine until I present a uialertcontroller
. When i present it,the barbutton
s are moving down from thier position.
Before presenting,everything was fine with barbuttons
When i present an alert,you can see the UIBarButtonItem
s are off their position
Code for creating barbuttonitem
s::
let editBtn:UIBarButtonItem = UIBarButtonItem(image: UIImage(named: IMAGE_EDIT_ICON), style: .plain, target: self, action: #selector(handleEditAction))
self.navigationItem.rightBarButtonItem = editBtn
Presenting UIAlertControlelr
as follows:
let alertController = UIAlertController(title: "Reset Password", message: "Please enter current password and create new password", preferredStyle: .alert)
let okAction = UIAlertAction(title: "Confirm", style: .default, handler: { [weak alertController] (_) in
})
let cancelAction = UIAlertAction(title: "Cancel", style: .default) { (_) in }
alertController.addAction(cancelAction)
alertController.addAction(okAction)
okAction.isEnabled = false
alertController.addTextField { (textField) in
textField.placeholder = "Current Password"
}
}
alertController.addTextField { (textField) in
textField.placeholder = "New Password"
}
}
alertController.addTextField { (textField) in
textField.placeholder = "Confirm Password"
textField.isSecureTextEntry = true
NotificationCenter.default.addObserver(forName: NSNotification.Name.UITextFieldTextDidChange, object:textField,
queue: OperationQueue.main) {
(notification) -> Void in
self.validateResetPassword(alertController: alertController,okAction: okAction)
}
}
self.present(alertController, animated: true, completion: nil)
Can someone help me to fix this. Thanks in advance
Upvotes: 0
Views: 71
Reputation: 16180
I recommend you to use Interface Builder(IB) to set UIBarButtonItems
.
You can also set Image via IB as well as Code.
-
let editBtn:UIBarButtonItem = UIBarButtonItem(image: UIImage(named: IMAGE_EDIT_ICON), style: .plain, target: self, action:#selector(handleEditAction)) self.navigationItem.rightBarButtonItem = editBtn
Upvotes: 0
Reputation: 8322
Replace your bar button as below :
let barButton = UIBarButtonItem(image: UIImage(named: "imageName"), style: .plain, target: self, action: #selector(self.YourSelectorTarget))
Upvotes: 1