diff --git a/README.md b/README.md index 1fd7f37..b1e084c 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ With `SwiftAlertView`, you can easily make your desired Alert View in some lines [CocoaPods](https://cocoapods.org) is a dependency manager for Cocoa projects. To integrate SwiftAlertView into your Xcode project using CocoaPods, specify it in your `Podfile`: ```ruby -pod 'SwiftAlertView', '~> 2.2.0' +pod 'SwiftAlertView', '~> 2.2.1' ``` #### Carthage @@ -23,7 +23,7 @@ pod 'SwiftAlertView', '~> 2.2.0' [Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate SwiftAlertView into your Xcode project using Carthage, specify it in your `Cartfile`: ```ogdl -github "https://github.com/dinhquan/SwiftAlertView" ~> 2.2.0 +github "https://github.com/dinhquan/SwiftAlertView" ~> 2.2.1 ``` #### Swift Package Manager @@ -34,7 +34,7 @@ Once you have your Swift package set up, adding SwiftAlertView as a dependency i ```swift dependencies: [ - .package(url: "https://github.com/dinhquan/SwiftAlertView", .upToNextMajor(from: "2.2.0")) + .package(url: "https://github.com/dinhquan/SwiftAlertView", .upToNextMajor(from: "2.2.1")) ] ``` @@ -60,14 +60,14 @@ Drag and drop the file named ```SwiftAlertView``` inside `Source` in your projec ### Showing an alert ```swift -SwiftAlertView.show(title: "Sample title", message: "Sample message", buttonTitles: "Cancel", "OK") +SwiftAlertView.show(title: "Title", message: "Message", buttonTitles: "Cancel", "OK") ``` Customization ```swift -SwiftAlertView.show(title: "Sample title", - message: "Sample message", +SwiftAlertView.show(title: "Title", + message: "Message", buttonTitles: "OK", "Cancel") { alert in alert.backgroundColor = .yellow alert.cancelButtonIndex = 1 @@ -78,8 +78,8 @@ SwiftAlertView.show(title: "Sample title", Handle button clicked events ```swift -SwiftAlertView.show(title: "Sample title", - message: "Sample message", +SwiftAlertView.show(title: "Title", + message: "Message", buttonTitles: "OK", "Cancel") { $0.style = .dark } @@ -91,17 +91,28 @@ SwiftAlertView.show(title: "Sample title", Add text fields ```swift -SwiftAlertView.show(title: "Sign in", buttonTitles: "Cancel", "Sign In") { alert in - alert.addTextField { textField in +SwiftAlertView.show(title: "Sign in", buttonTitles: "Cancel", "Sign In") { alertView in + alertView.addTextField { textField in textField.placeholder = "Username" } - alert.addTextField { textField in + alertView.addTextField { textField in textField.placeholder = "Password" } + alertView.isEnabledValidationLabel = true + alertView.isDismissOnActionButtonClicked = false } .onActionButtonClicked { alert, buttonIndex in let username = alert.textField(at: 0)?.text ?? "" - print("Username: ", username) + if username.isEmpty { + alert.validationLabel.text = "Username is incorrect" + } else { + alert.dismiss() + } +} +.onTextChanged { _, text, index in + if index == 0 { + print("Username text changed: ", text ?? "") + } } ``` @@ -120,7 +131,7 @@ SwiftAlertView.show(contentView: customView, buttonTitles: "OK") Initialize an alert ```swift -let alertView = SwiftAlertView(title: "Sample Title", message: "Sample Message", buttonTitles: "Cancel", "Button 1", "Button 2", "Button 3") +let alertView = SwiftAlertView(title: "Title", message: "Message", buttonTitles: "Cancel", "Button 1", "Button 2", "Button 3") let alertView = SwiftAlertView(contentView: customView, buttonTitles: "OK") @@ -218,6 +229,10 @@ public var textFieldSideMargin: CGFloat = 15.0 public var textFieldBottomMargin: CGFloat = 15.0 public var textFieldSpacing: CGFloat = 10.0 public var isFocusTextFieldWhenShowing = true +public var isEnabledValidationLabel = false +public var validationLabel: UILabel! // access to validation label to customize font, color +public var validationLabelTopMargin: CGFloat = 8.0 +public var validationLabelSideMargin: CGFloat = 15.0 ``` ## Contributing diff --git a/Source/SwiftAlertView.swift b/Source/SwiftAlertView.swift index ba2d7d9..08a7e30 100644 --- a/Source/SwiftAlertView.swift +++ b/Source/SwiftAlertView.swift @@ -61,14 +61,7 @@ public class SwiftAlertView: UIView { public var cancelButtonIndex = 0 { // default is 0, set this property if you want to change the position of cancel button didSet { - for i in 0.. Bool { // Override point for customization after application launch. - return true + return true } } diff --git a/SwiftAlertView/Images/demo.png b/SwiftAlertView/Images/demo.png index 6cee9dc..0206779 100644 Binary files a/SwiftAlertView/Images/demo.png and b/SwiftAlertView/Images/demo.png differ diff --git a/SwiftAlertView/ViewController.swift b/SwiftAlertView/ViewController.swift index 82eb426..9e00d42 100644 --- a/SwiftAlertView/ViewController.swift +++ b/SwiftAlertView/ViewController.swift @@ -43,7 +43,6 @@ final class ViewController: UITableViewController { SwiftAlertView.show(title: "Title", message: "Message", buttonTitles: "Button 1", "Button 2", "Button 3", "Cancel") { alertView in - alertView.style = .auto alertView.cancelButtonIndex = 3 alertView.buttonTitleColor = UIColor(red: 0.8764, green: 0.5, blue: 0.3352, alpha: 1) alertView.addTextField { textField in @@ -58,13 +57,14 @@ final class ViewController: UITableViewController { case 2: SwiftAlertView.show(title: "Sign in", buttonTitles: "Cancel", "Sign In") { alertView in alertView.addTextField { textField in - textField.placeholder = "Username" + textField.attributedPlaceholder = NSAttributedString(string: "Username", attributes: [.foregroundColor: UIColor.gray]) } alertView.addTextField { textField in - textField.placeholder = "Password" + textField.attributedPlaceholder = NSAttributedString(string: "Password", attributes: [.foregroundColor: UIColor.gray]) } alertView.isEnabledValidationLabel = true alertView.isDismissOnActionButtonClicked = false + alertView.style = .dark } .onActionButtonClicked { alert, buttonIndex in let username = alert.textField(at: 0)?.text ?? ""