Skip to content

Commit

Permalink
Update version
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhquan committed Jan 14, 2022
1 parent 87f058a commit 601c049
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 26 deletions.
41 changes: 28 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ 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

[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
Expand All @@ -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"))
]
```

Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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 ?? "")
}
}
```

Expand All @@ -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")

Expand Down Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 deletions Source/SwiftAlertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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..<buttons.count {
let button = buttons[i]
if i == cancelButtonIndex {
button.titleLabel?.font = .boldSystemFont(ofSize: button.titleLabel?.font.pointSize ?? 17)
} else {
button.titleLabel?.font = .systemFont(ofSize: button.titleLabel?.font.pointSize ?? 17)
}
}
updateCancelButtonIndex()
}
}
public var buttonTitleColor = UIColor(red: 0, green: 0.478431, blue: 1, alpha: 1) // to change the title color of all buttons
Expand Down Expand Up @@ -585,6 +578,17 @@ extension SwiftAlertView {
}
}

private func updateCancelButtonIndex() {
for i in 0..<buttons.count {
let button = buttons[i]
if i == cancelButtonIndex {
button.titleLabel?.font = .boldSystemFont(ofSize: button.titleLabel?.font.pointSize ?? 17)
} else {
button.titleLabel?.font = .systemFont(ofSize: button.titleLabel?.font.pointSize ?? 17)
}
}
}

private func updateAlertStyle() {
titleLabel.textColor = color(light: .black, dark: .white)
messageLabel.textColor = color(light: .black, dark: .white)
Expand Down
2 changes: 1 addition & 1 deletion SwiftAlertView.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "SwiftAlertView"
s.version = "2.2.0"
s.version = "2.2.1"
s.summary = "A powerful customizable Alert View written in Swift."
s.description = <<-DESC
SwiftAlertView is a powerful customizable Alert View written in Swift. With SwiftAlertView, you can easily make your desired Alert View in some lines of code.
Expand Down
12 changes: 12 additions & 0 deletions SwiftAlertView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
146BEE6E272930EB0004D971 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 146BEE6C272930EB0004D971 /* LaunchScreen.storyboard */; };
146BEE76272931A80004D971 /* CustomView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 146BEE75272931A80004D971 /* CustomView.xib */; };
146BEE792729328C0004D971 /* SwiftAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 146BEE782729328C0004D971 /* SwiftAlertView.swift */; };
14B4714B279106A800634E54 /* SwiftAlertView.podspec in Resources */ = {isa = PBXBuildFile; fileRef = 14B47147279106A700634E54 /* SwiftAlertView.podspec */; };
14B4714D279106A800634E54 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 14B47149279106A800634E54 /* LICENSE */; };
14B4714E279106A800634E54 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 14B4714A279106A800634E54 /* README.md */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -27,6 +30,9 @@
146BEE75272931A80004D971 /* CustomView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CustomView.xib; sourceTree = "<group>"; };
146BEE782729328C0004D971 /* SwiftAlertView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftAlertView.swift; sourceTree = "<group>"; };
146BEE7A272932F20004D971 /* Marker Felt.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Marker Felt.ttf"; sourceTree = "<group>"; };
14B47147279106A700634E54 /* SwiftAlertView.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SwiftAlertView.podspec; sourceTree = "<group>"; };
14B47149279106A800634E54 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
14B4714A279106A800634E54 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -43,6 +49,9 @@
146BEE55272930E90004D971 = {
isa = PBXGroup;
children = (
14B47149279106A800634E54 /* LICENSE */,
14B4714A279106A800634E54 /* README.md */,
14B47147279106A700634E54 /* SwiftAlertView.podspec */,
146BEE772729328C0004D971 /* Source */,
146BEE60272930E90004D971 /* SwiftAlertView */,
146BEE5F272930E90004D971 /* Products */,
Expand Down Expand Up @@ -137,8 +146,11 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
14B4714D279106A800634E54 /* LICENSE in Resources */,
146BEE6E272930EB0004D971 /* LaunchScreen.storyboard in Resources */,
146BEE76272931A80004D971 /* CustomView.xib in Resources */,
14B4714E279106A800634E54 /* README.md in Resources */,
14B4714B279106A800634E54 /* SwiftAlertView.podspec in Resources */,
146BEE6B272930EB0004D971 /* Assets.xcassets in Resources */,
146BEE69272930E90004D971 /* Main.storyboard in Resources */,
);
Expand Down
2 changes: 1 addition & 1 deletion SwiftAlertView/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.

return true
return true
}

}
Expand Down
Binary file modified SwiftAlertView/Images/demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions SwiftAlertView/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ?? ""
Expand Down

0 comments on commit 601c049

Please sign in to comment.