Barbuttons 正在离开位置
Barbuttons are moving off the position
在我出示 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)
谁能帮我解决这个问题。
提前致谢
按如下所示替换您的栏按钮:
let barButton = UIBarButtonItem(image: UIImage(named: "imageName"), style: .plain, target: self, action: #selector(self.YourSelectorTarget))
我建议您使用 Interface Builder(IB) 来设置 UIBarButtonItems
。
也可以通过IB设置图片,也可以通过代码设置。
- 在界面生成器上设置 UIBarButtonItem
- 使用代码:
-
let editBtn:UIBarButtonItem = UIBarButtonItem(image: UIImage(named: IMAGE_EDIT_ICON), style: .plain, target: self, action:#selector(handleEditAction)) self.navigationItem.rightBarButtonItem = editBtn
在我出示 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)
谁能帮我解决这个问题。 提前致谢
按如下所示替换您的栏按钮:
let barButton = UIBarButtonItem(image: UIImage(named: "imageName"), style: .plain, target: self, action: #selector(self.YourSelectorTarget))
我建议您使用 Interface Builder(IB) 来设置 UIBarButtonItems
。
也可以通过IB设置图片,也可以通过代码设置。
- 在界面生成器上设置 UIBarButtonItem
- 使用代码:
-
let editBtn:UIBarButtonItem = UIBarButtonItem(image: UIImage(named: IMAGE_EDIT_ICON), style: .plain, target: self, action:#selector(handleEditAction)) self.navigationItem.rightBarButtonItem = editBtn