在我提出uialertcontroller
之前,一切都很好。当我呈现它时,barbutton
正从他们的位置向下移动。
Before presenting,everything was fine with barbuttons
When i present an alert,you can see the UIBarButtonItem
s are off their position
创建barbuttonitem
s ::
let editBtn:UIBarButtonItem = UIBarButtonItem(image: UIImage(named: IMAGE_EDIT_ICON), style: .plain, target: self, action: #selector(handleEditAction))
self.navigationItem.rightBarButtonItem = editBtn
如下所示展示UIAlertControlelr
:
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)
有人可以帮我解决这个问题。 提前致谢
答案 0 :(得分:1)
如下所示更换栏按钮:
let barButton = UIBarButtonItem(image: UIImage(named: "imageName"), style: .plain, target: self, action: #selector(self.YourSelectorTarget))
答案 1 :(得分:0)
我建议您使用 Interface Builder (IB)来设置UIBarButtonItems
。
您也可以通过IB和代码设置图像。
-
let editBtn:UIBarButtonItem = UIBarButtonItem(image: UIImage(named: IMAGE_EDIT_ICON), style: .plain, target: self, action:#selector(handleEditAction)) self.navigationItem.rightBarButtonItem = editBtn