Comments (5)
Hi there. Really simple. Access to the stack view of alertVC and change the axis (vertical or horizontal)
from pmalertcontroller.
I think you misunderstood my problem.
Since buttons and the textfield are on the same stack view, if you change the axis to horizontal every element will be in the same line. That's not the desired outcome. Textfield should be in a single line and buttons should be horizontal.
from pmalertcontroller.
Sorry, I had not noticed that you also have a text field inside. In this case, you can't change the alignment for single components, because every component (text fields and buttons) is inside the same stack view.
from pmalertcontroller.
Hi there !
Maybe it's a little late for you, but I was facing the same problem so I create an extension to make this possible :-)
extension PMAlertController {
static func initWithTextFieldValidation(title: String,
description: String,
textField: UITextField,
confirmButtonTitle: String,
cancelButtonTitle: String,
confirmButtonAction: ((PMAlertController) -> Void)? = nil,
cancelButtonAction: ((PMAlertController) -> Void)? = nil) -> PMAlertController {
// Init the alert
let passwordAlert = PMAlertController(title: title, description: description, image: nil, style: .alert)
passwordAlert.gravityDismissAnimation = false
// Create the first fieldStack with the textField and set some insets on side
let fieldStack = UIStackView(arrangedSubviews: [textField])
fieldStack.layoutMargins = UIEdgeInsets(top: 0, left: 8, bottom: 0, right: 8)
// Init actions
let cancelAction = PMAlertAction(title: cancelButtonTitle, style: .cancel, action: { () -> Void in
if let action = cancelButtonAction {
action(passwordAlert)
} else {
passwordAlert.dismiss(animated: true, completion: nil)
}
})
let confirmAction = PMAlertAction(title: confirmButtonTitle, style: .default, action: { () in
confirmButtonAction?(passwordAlert)
})
// Create second Stack with actions and set his axis to horizontal
let buttonsStack = UIStackView(arrangedSubviews: [cancelAction, confirmAction])
buttonsStack.axis = .horizontal
// Add constraint to be sure two buttons have the same width
buttonsStack.addConstraint(NSLayoutConstraint(item: cancelAction, attribute: .width, relatedBy: .equal, toItem: confirmAction, attribute: .width, multiplier: 1, constant: 0))
// set the alert's StackView axis to vertical and add stacks
passwordAlert.alertActionStackView.axis = .vertical
passwordAlert.alertActionStackView.addArrangedSubview(fieldStack)
passwordAlert.alertActionStackView.addArrangedSubview(buttonsStack)
passwordAlert.alertActionStackViewHeightConstraint.constant = 62 * CGFloat(passwordAlert.alertActionStackView.arrangedSubviews.count)
return passwordAlert
}
}
And here is the way to use it
let passwordField = UITextField()
passwordField.font = UIFont.preferredFont(forTextStyle: .body)
passwordField.isSecureTextEntry = true
passwordField.textColor = UIColor.bodyGray
passwordField.placeholder = "Mot de passe"
passwordField.textAlignment = .center
let fieldAlert = PMAlertController.initWithTextFieldValidation(title: "Connexion", description: "Entrez votre mot de passe", textField: passwordField, confirmButtonTitle: "Confirmer", cancelButtonTitle: "Annuler",
confirmButtonAction: { alert in
//TODO CONFIRM BUTTON
},
cancelButtonAction: { alert in
alert.dismiss(animated: true, completion: nil)
})
self.present(fieldAlert, animated: true, completion: nil)
Hope this can help !
And thank for this very nice lib ! It's just missing this case ! :-)
from pmalertcontroller.
You could also add the textfield as subview of the contentStackView
let textField = TextField(frame: CGRect(x: 0, y: 0, width: 230, height: 40))
textField.placeholder = "Enter your email address"
textField.backgroundColor = ColorCompatibility.lightBackground
textField.layer.cornerRadius = 8
textField.font = UIFont.systemFont(ofSize: 15)
textField.keyboardType = UIKeyboardType.emailAddress
textField.autocapitalizationType = .none
textField.accessibilityIdentifier = "forgotPasswordInput"
textField.addTarget(self, action: #selector(self.alertTextFieldDidChange(field:)), for: UIControl.Event.editingChanged)
alert.alertContentStackView.addArrangedSubview(textField)
from pmalertcontroller.
Related Issues (20)
- Lots of Xcode 10 errors HOT 2
- Change Button Colour When Selected HOT 3
- Send notification on alert dismiss
- Not presenting nested Alerts HOT 1
- Invalid Task Error after Pod Install HOT 9
- Turning off auto dismiss when tapping button HOT 2
- Can I keep the alert portrait even though the view is in landscape? HOT 2
- Require textfield value HOT 3
- xcode10.2 build error HOT 2
- Can I override the viewDidDisappear method in PMAlertController HOT 1
- PMAlertController textfield access via objc HOT 4
- Build error when not using dynamic framework in podfile
- Black background when using Tabbar HOT 4
- Swift Compiler Error in Swift 5 HOT 2
- Display two alertVC
- Can't Set Attributed String
- How to customize like fonts?
- App Store Connect operation error HOT 2
- Missing SPM Support HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pmalertcontroller.