Skip to content

Commit

Permalink
Merge branch 'release/0.1.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
danlozano committed Jul 26, 2016
2 parents ab8bdb3 + 254a0e2 commit cbe5b29
Show file tree
Hide file tree
Showing 19 changed files with 386 additions and 277 deletions.
36 changes: 36 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
disabled_rules:
- line_length
- missing_docs
- function_parameter_count
opt_in_rules:
- empty_count
- missing_docs
included:
excluded:
- docs
- PresentrExample
- PresentrTests
force_cast: warning
force_try:
severity: warning
line_length: 150
type_body_length:
- 300 # warning
- 400 # error
file_length:
warning: 500
error: 1200
type_name:
min_length: 4 # only warning
max_length: # warning and error
warning: 40
error: 50
excluded: iPhone # excluded via string
variable_name:
min_length:
error: 1 # only error
excluded: # excluded via string array
- id
- URL
- GlobalAPIKey
reporter: "json" # reporter type (xcode, json, csv, checkstyle)
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
### What's New

#### 0.1.8
- .FullScreen PresentationType
- Ability to set animation on/off for dismissOnTap

#### 0.1.7
- Ability to set dismiss transition type
- Modify background color & opacity
- Add blur to background

#### 0.1.6
- Custom PresentationType's
- Round corners option
4 changes: 2 additions & 2 deletions Presentr.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Presentr"
s.version = "0.1.7"
s.version = "0.1.8"
s.summary = "A simple Swift wrapper for typical custom view controller presentations."
s.description = <<-DESC
A micro framework created in Swift. Simplifies creating custom view controller presentations. Specially the typical ones we use which are a popup, an alert, or a any non-full-screen modal. Abstracts having to deal with custom presentation controllers and transitioning delegates
Expand All @@ -10,7 +10,7 @@ Pod::Spec.new do |s|
s.author = { "Daniel Lozano" => "[email protected]" }
s.social_media_url = "http://twitter.com/danlozanov"
s.platform = :ios, "8.0"
s.source = { :git => "https://github.com/icalialabs/Presentr.git", :tag => "0.1.7" }
s.source = { :git => "https://github.com/icalialabs/Presentr.git", :tag => "0.1.8" }
s.source_files = "Presentr/**/*.{swift}"
s.resources = "Presentr/**/*.{xib,ttf}"
end
120 changes: 60 additions & 60 deletions Presentr/AlertViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,48 @@ import UIKit
public typealias AlertActionHandler = (() -> Void)

/// Describes each action that is going to be shown in the 'AlertViewController'
public class AlertAction{
public class AlertAction {

let title: String
let style: AlertActionStyle
let handler: AlertActionHandler?

/**
Initialized an 'AlertAction'
- parameter title: The title for the action, that will be used as the title for a button in the alert controller
- parameter style: The style for the action, that will be used to style a button in the alert controller.
- parameter handler: The handler for the action, that will be called when the user clicks on a button in the alert controller.
- returns: An inmutable AlertAction object
*/
public init(title: String, style: AlertActionStyle, handler: AlertActionHandler?){
public init(title: String, style: AlertActionStyle, handler: AlertActionHandler?) {
self.title = title
self.style = style
self.handler = handler
}

}

/**
Describes the style for an action, that will be used to style a button in the alert controller.
- Default: Green text label. Meant to draw attention to the action.
- Cancel: Gray text label. Meant to be neutral.
- Destructive: Red text label. Meant to warn the user about the action.
*/
public enum AlertActionStyle{
public enum AlertActionStyle {

case Default
case Cancel
case Destructive

/**
Decides which color to use for each style
- returns: UIColor representing the color for the current style
*/
func color() -> UIColor{
func color() -> UIColor {
switch self {
case .Default:
return ColorPalette.greenColor
Expand All @@ -62,59 +62,59 @@ public enum AlertActionStyle{
return ColorPalette.redColor
}
}

}

private enum Font: String {

case Montserrat = "Montserrat-Regular"
case SourceSansPro = "SourceSansPro-Regular"
func font(size: CGFloat = 15.0) -> UIFont{

func font(size: CGFloat = 15.0) -> UIFont {
return UIFont(name: self.rawValue, size: size)!
}

}

private struct ColorPalette {

static let grayColor = UIColor(red: 151.0/255.0, green: 151.0/255.0, blue: 151.0/255.0, alpha: 1)
static let greenColor = UIColor(red: 58.0/255.0, green: 213.0/255.0, blue: 91.0/255.0, alpha: 1)
static let redColor = UIColor(red: 255.0/255.0, green: 103.0/255.0, blue: 100.0/255.0, alpha: 1)

}

/// UIViewController subclass that displays the alert
public class AlertViewController: UIViewController {

/// Text that will be used as the title for the alert
public var titleText: String?
/// Text that will be used as the body for the alert
public var bodyText: String?

/// If set to false, alert wont auto-dismiss the controller when an action is clicked. Dismissal will be up to the action's handler. Default is true.
public var autoDismiss: Bool = true
/// If autoDismiss is set to true, then set this property if you want the dismissal to be animated. Default is true.
public var dismissAnimated: Bool = true

private var actions = [AlertAction]()

@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var bodyLabel: UILabel!
@IBOutlet weak var firstButton: UIButton!
@IBOutlet weak var secondButton: UIButton!
@IBOutlet weak var firstButtonWidthConstraint: NSLayoutConstraint!

override public func viewDidLoad() {
super.viewDidLoad()
if actions.isEmpty{

if actions.isEmpty {
let okAction = AlertAction(title: "ok 🕶", style: .Default, handler: nil)
addAction(okAction)
}

loadFonts()

setupFonts()
setupLabels()
setupButtons()
Expand All @@ -123,9 +123,9 @@ public class AlertViewController: UIViewController {
override public func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}

override public func updateViewConstraints() {
if actions.count == 1{
if actions.count == 1 {
// If only one action, second button will have been removed from superview
// So, need to add constraint for first button trailing to superview
if let constraint = firstButtonWidthConstraint {
Expand All @@ -140,51 +140,51 @@ public class AlertViewController: UIViewController {
}
super.updateViewConstraints()
}

// MARK: AlertAction's

/**
Adds an 'AlertAction' to the alert controller. There can be maximum 2 actions. Any more will be ignored. The order is important.
- parameter action: The 'AlertAction' to be added
*/
public func addAction(action: AlertAction){
public func addAction(action: AlertAction) {
guard actions.count < 2 else { return }
actions += [action]
}

// MARK: Setup
private func setupFonts(){

private func setupFonts() {
titleLabel.font = Font.Montserrat.font()
bodyLabel.font = Font.SourceSansPro.font()
firstButton.titleLabel?.font = Font.Montserrat.font(11.0)
secondButton.titleLabel?.font = Font.Montserrat.font(11.0)
}
private func setupLabels(){

private func setupLabels() {
titleLabel.text = titleText ?? "Alert"
bodyLabel.text = bodyText ?? "This is an alert."
}
private func setupButtons(){

private func setupButtons() {
guard let firstAction = actions.first else { return }
apply(firstAction, toButton: firstButton)
if actions.count == 2{
if actions.count == 2 {
let secondAction = actions.last!
apply(secondAction, toButton: secondButton)
}else{
} else {
secondButton.removeFromSuperview()
}
}
private func apply(action: AlertAction, toButton: UIButton){

private func apply(action: AlertAction, toButton: UIButton) {
let title = action.title.uppercaseString
let style = action.style
toButton.setTitle(title, forState: .Normal)
toButton.setTitleColor(style.color(), forState: .Normal)
}

// MARK: IBAction's

@IBAction func didSelectFirstAction(sender: AnyObject) {
Expand All @@ -194,40 +194,40 @@ public class AlertViewController: UIViewController {
}
dismiss()
}

@IBAction func didSelectSecondAction(sender: AnyObject) {
guard let secondAction = actions.last where actions.count == 2 else { return }
if let handler = secondAction.handler {
handler()
}
dismiss()
}

// MARK: Helper's
func dismiss(){

func dismiss() {
guard autoDismiss else { return }
dismissViewControllerAnimated(dismissAnimated, completion: nil)
}

}

// MARK: - Font Loading

extension AlertViewController {
struct PresentrStatic{

struct PresentrStatic {
static var onceToken: dispatch_once_t = 0
}
private func loadFonts(){

private func loadFonts() {
dispatch_once(&PresentrStatic.onceToken) {
self.loadFont(Font.Montserrat.rawValue)
self.loadFont(Font.SourceSansPro.rawValue)
}
}
private func loadFont(name: String) -> Bool{

private func loadFont(name: String) -> Bool {
let bundle = NSBundle(forClass: self.dynamicType)
guard let fontPath = bundle.pathForResource(name, ofType: "ttf") else {
return false
Expand All @@ -241,10 +241,10 @@ extension AlertViewController {
print("Error loading font. Font is possibly already registered.")
return false
}
}else{
} else {
return false
}
return true
}

}

0 comments on commit cbe5b29

Please sign in to comment.