Skip to content

Commit

Permalink
Merge pull request #7 from sgr-ksmt/release/1.1
Browse files Browse the repository at this point in the history
1.1
  • Loading branch information
sgr-ksmt authored Apr 30, 2017
2 parents af51787 + 10b05bb commit 274d415
Show file tree
Hide file tree
Showing 11 changed files with 257 additions and 91 deletions.
2 changes: 1 addition & 1 deletion Alertift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Alertift"
s.version = "1.0.1"
s.version = "1.1"
s.summary = "UIAlertControlelr wrapper for Swift."
s.homepage = "https://github.com/sgr-ksmt/Alertift"
# s.screenshots = ""
Expand Down
8 changes: 4 additions & 4 deletions Alertift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
4D13C7B11EB22B8F007BBB43 /* Action.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D13C7AB1EB22B8F007BBB43 /* Action.swift */; };
4D13C7B21EB22B8F007BBB43 /* ActionSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D13C7AC1EB22B8F007BBB43 /* ActionSheet.swift */; };
4D13C7B31EB22B8F007BBB43 /* Alert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D13C7AD1EB22B8F007BBB43 /* Alert.swift */; };
4D13C7B41EB22B8F007BBB43 /* AlertBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D13C7AE1EB22B8F007BBB43 /* AlertBase.swift */; };
4D13C7B51EB22B8F007BBB43 /* Alertift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D13C7AF1EB22B8F007BBB43 /* Alertift.swift */; };
4D13C7B61EB22B8F007BBB43 /* InnerAlertController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D13C7B01EB22B8F007BBB43 /* InnerAlertController.swift */; };
4D13C7BF1EB320D4007BBB43 /* ActionHandlerBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D13C7BE1EB320D4007BBB43 /* ActionHandlerBuilder.swift */; };
4D13C7C11EB32AE6007BBB43 /* Debug.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D13C7C01EB32AE6007BBB43 /* Debug.swift */; };
4D13C7C51EB5DFB7007BBB43 /* AlertType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D13C7C41EB5DFB7007BBB43 /* AlertType.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -25,11 +25,11 @@
4D13C7AB1EB22B8F007BBB43 /* Action.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Action.swift; sourceTree = "<group>"; };
4D13C7AC1EB22B8F007BBB43 /* ActionSheet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionSheet.swift; sourceTree = "<group>"; };
4D13C7AD1EB22B8F007BBB43 /* Alert.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Alert.swift; sourceTree = "<group>"; };
4D13C7AE1EB22B8F007BBB43 /* AlertBase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlertBase.swift; sourceTree = "<group>"; };
4D13C7AF1EB22B8F007BBB43 /* Alertift.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Alertift.swift; sourceTree = "<group>"; };
4D13C7B01EB22B8F007BBB43 /* InnerAlertController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InnerAlertController.swift; sourceTree = "<group>"; };
4D13C7BE1EB320D4007BBB43 /* ActionHandlerBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionHandlerBuilder.swift; sourceTree = "<group>"; };
4D13C7C01EB32AE6007BBB43 /* Debug.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Debug.swift; sourceTree = "<group>"; };
4D13C7C41EB5DFB7007BBB43 /* AlertType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlertType.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -73,13 +73,13 @@
isa = PBXGroup;
children = (
4D13C7AF1EB22B8F007BBB43 /* Alertift.swift */,
4D13C7AE1EB22B8F007BBB43 /* AlertBase.swift */,
4D13C7AD1EB22B8F007BBB43 /* Alert.swift */,
4D13C7AC1EB22B8F007BBB43 /* ActionSheet.swift */,
4D13C7AB1EB22B8F007BBB43 /* Action.swift */,
4D13C7B01EB22B8F007BBB43 /* InnerAlertController.swift */,
4D13C7BE1EB320D4007BBB43 /* ActionHandlerBuilder.swift */,
4D13C7C01EB32AE6007BBB43 /* Debug.swift */,
4D13C7C41EB5DFB7007BBB43 /* AlertType.swift */,
);
path = Sources;
sourceTree = "<group>";
Expand Down Expand Up @@ -167,8 +167,8 @@
4D13C7B31EB22B8F007BBB43 /* Alert.swift in Sources */,
4D13C7BF1EB320D4007BBB43 /* ActionHandlerBuilder.swift in Sources */,
4D13C7B61EB22B8F007BBB43 /* InnerAlertController.swift in Sources */,
4D13C7B41EB22B8F007BBB43 /* AlertBase.swift in Sources */,
4D13C7B11EB22B8F007BBB43 /* Action.swift in Sources */,
4D13C7C51EB5DFB7007BBB43 /* AlertType.swift in Sources */,
4D13C7C11EB32AE6007BBB43 /* Debug.swift in Sources */,
4D13C7B51EB22B8F007BBB43 /* Alertift.swift in Sources */,
4D13C7B21EB22B8F007BBB43 /* ActionSheet.swift in Sources */,
Expand Down
36 changes: 21 additions & 15 deletions Demo/Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ class ViewController: UIViewController {
}
}

override func viewDidLoad() {
super.viewDidLoad()
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
Alertift.alert(title: "Alertift", message: "Alertift is swifty, modern, and awesome UIAlertController wrapper.")
.titleTextColor(.red)
.messageTextColor(.blue)
.action(.default(""))
.action(.default(""))
.show(on: self)
Expand Down Expand Up @@ -96,22 +102,22 @@ class ViewController: UIViewController {
.show()
}
private func showActionSheet(source: UIView, frame: CGRect) {
Alertift.actionSheet(message: "Which food do you like?")
.popover(sourceView: source, sourceRect: frame)
.action(.default("🍣"))
.action(.default("🍎"))
.action(.default("🍖"))
.action(.default("🍅"))
.action(.cancel("None of them"))
.finally { action, index in
if action.style == .cancel {
return
Alertift.actionSheet(message: "Which food do you like?")
.popover(sourceView: source, sourceRect: frame)
.action(.default("🍣"))
.action(.default("🍎"))
.action(.default("🍖"))
.action(.default("🍅"))
.action(.cancel("None of them"))
.finally { action, index in
if action.style == .cancel {
return
}
Alertift.alert(message: "\(index). \(action.title!)")
.action(.default("OK"))
.show()
}
Alertift.alert(message: "\(index). \(action.title!)")
.action(.default("OK"))
.show()
}
.show()
.show()
}
}

Binary file added Documents/img6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Alertift.alert(title: "Alertift", message: "Alertift is swifty, modern, and awes
- Method chain
- UITextField support
- iPad support(Action Sheet, popover)
- Can change title/message/button text/ background color. (**without** private APIs.)

## Examples

Expand Down Expand Up @@ -115,6 +116,44 @@ Alertift.actionSheet(message: "Which food do you like?")

![img5](Documents/img5.png)

### Change colors

```swift
Alertift.alert(title: "Red color title", message: "Message text color is blue")
.titleTextColor(.red)
.messageTextColor(.blue)
.backgroundColor(.lightGray)
.buttonTextColor(.orange)
.action(.default("Orange"))
.show()
```

![img6](Documents/img6.png)

```swift
public func backgroundColor(_ color: UIColor?) -> Self
public func buttonTextColor(_ color: UIColor?) -> Self
public func titleTextColor(_ color: UIColor?) -> Self
public func messageTextColor(_ color: UIColor?) -> Self
```

#### Always change color

If you want to change Alertift's alert(action sheet) color always,
set color to `static var`.

```swift
Alertift.Alert.titleTextColor = .red
Alertift.ActionSheet.backgroundColor = .gray
```

```swift
static var backgroundColor: UIColor? { get set }
static var buttonTextColor: UIColor? { get set }
static var titleTextColor: UIColor? { get set }
static var messageTextColor: UIColor? { get set }
```


## Requirements
- iOS 9.0+
Expand Down
15 changes: 13 additions & 2 deletions Sources/ActionSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,26 @@ import Foundation

extension Alertift {
/// ActionSheet
final public class ActionSheet: AlertBase {
final public class ActionSheet: AlertType, _AlertType {

var _alertController: InnerAlertController!
public var alertController: UIAlertController {
return _alertController as UIAlertController
}

public static var backgroundColor: UIColor?
public static var buttonTextColor: UIColor?
public static var titleTextColor: UIColor?
public static var messageTextColor: UIColor?

/// Make action sheet
///
/// - Parameters:
/// - title: The title of the alert. Use this string to get the user’s attention and communicate the reason for the alert.
/// - message: Descriptive text that provides additional details about the reason for the alert.
/// - Returns: Instance of **ActionSheet**
public init(title: String? = nil, message: String? = nil) {
super.init(title: title, message: message, style: .actionSheet)
buildAlertControlelr(title: title, message: message, style: .actionSheet)
}

/// Add action to alertController
Expand Down
14 changes: 12 additions & 2 deletions Sources/Alert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,31 @@ import Foundation

extension Alertift {
/// Alert
final public class Alert: AlertBase {
final public class Alert: AlertType, _AlertType {
/// TextFieldHandler
public typealias TextFieldHandler = ((UITextField, Int) -> Void)

/// ActionWithTextFieldsHandler
public typealias ActionWithTextFieldsHandler = ([UITextField]?) -> Void

var _alertController: InnerAlertController!
public var alertController: UIAlertController {
return _alertController as UIAlertController
}

public static var backgroundColor: UIColor?
public static var buttonTextColor: UIColor?
public static var titleTextColor: UIColor?
public static var messageTextColor: UIColor?

/// Make alert
///
/// - Parameters:
/// - title: The title of the alert. Use this string to get the user’s attention and communicate the reason for the alert.
/// - message: Descriptive text that provides additional details about the reason for the alert.
/// - Returns: Instance of **Alert**
public init(title: String? = nil, message: String? = nil) {
super.init(title: title, message: message, style: .alert)
buildAlertControlelr(title: title, message: message, style: .alert)
}

/// Add alertAction to alertController
Expand Down
66 changes: 0 additions & 66 deletions Sources/AlertBase.swift

This file was deleted.

Loading

0 comments on commit 274d415

Please sign in to comment.