Skip to content

Commit

Permalink
Merge pull request #9 from sgr-ksmt/release/1.2
Browse files Browse the repository at this point in the history
Release/1.2
  • Loading branch information
sgr-ksmt authored May 2, 2017
2 parents 274d415 + 80451af commit 79570b2
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 12 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.1"
s.version = "1.2"
s.summary = "UIAlertControlelr wrapper for Swift."
s.homepage = "https://github.com/sgr-ksmt/Alertift"
# s.screenshots = ""
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ 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.)
- Can change title/message/button text/ background color **without** using private APIs.
- Can change title/message's alignment **without** using private APIs.

## Examples

Expand Down
13 changes: 12 additions & 1 deletion Sources/ActionSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,23 @@ extension Alertift {
/// - Parameters:
/// - view: sourceView
/// - rect: sourceRect
/// - Returns: MySelf
/// - Returns: Myself
public func popover(sourceView view: UIView?, sourceRect rect: CGRect) -> Self {
_alertController.popoverPresentationController?.sourceView = view
_alertController.popoverPresentationController?.sourceRect = rect
return self
}

/// Add barButtonItem to **popoverPresentationController**.
///
/// If you want to use action sheet on iPad, you have to use this method.
/// - Parameters:
/// - barButtonItem: UIBarButtonItem
/// - Returns: Myself
public func popover(barButtonItem: UIBarButtonItem?) -> Self {
_alertController.popoverPresentationController?.barButtonItem = barButtonItem
return self
}

deinit {
Debug.log()
Expand Down
19 changes: 19 additions & 0 deletions Sources/AlertType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,25 @@ extension AlertType {
return self
}

/// Change text alignment of title
///
/// - Parameter alignment: NSTextAlignment
/// - Returns: Myself
public func titleTextAlignment(_ alignment: NSTextAlignment) -> Self {
_alertController.titleTextAlignment = alignment
return self
}

/// Change text alignment of message
///
/// - Parameter alignment: NSTextAlignment
/// - Returns: Myself
public func messageTextAlignment(_ alignment: NSTextAlignment) -> Self {
_alertController.messageTextAlignment = alignment
return self
}


/// Show alert (or action sheet).
///
/// - Parameters:
Expand Down
30 changes: 21 additions & 9 deletions Sources/InnerAlertController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ class InnerAlertController: UIAlertController {
var alertBackgroundColor: UIColor?
var titleTextColor: UIColor? = .black
var messageTextColor: UIColor? = .black

var titleTextAlignment: NSTextAlignment = .center
var messageTextAlignment: NSTextAlignment = .center


/// Register UITextFieldTextDidChange notification
///
/// - Parameter textField: textField
Expand Down Expand Up @@ -65,8 +68,8 @@ class InnerAlertController: UIAlertController {
super.viewWillLayoutSubviews()

adaptBackgroundColor()
adaptTitleColor()
adaptMessageColor()
updateTitleLabel()
updateMessageLabel()
}

private func adaptBackgroundColor() {
Expand All @@ -80,19 +83,28 @@ class InnerAlertController: UIAlertController {
}
}

private func adaptTitleColor() {
if let title = title, let titleLabel = searchLabel(from: title) {
print(titleLabel.textColor)
var titleLabel: UILabel? {
return title.flatMap(searchLabel(from:))
}

var messageLabel: UILabel? {
return message.flatMap(searchLabel(from:))
}

private func updateTitleLabel() {
if let titleLabel = titleLabel {
titleLabel.textColor = titleTextColor
titleLabel.textAlignment = titleTextAlignment
}
}

private func adaptMessageColor() {
if let message = message, let messageLabel = searchLabel(from: message) {
private func updateMessageLabel() {
if let messageLabel = messageLabel {
messageLabel.textColor = messageTextColor
messageLabel.textAlignment = messageTextAlignment
}
}

private var mainView: UIView? {
return view.subviews.first?.subviews.first?.subviews.first
}
Expand Down

0 comments on commit 79570b2

Please sign in to comment.