├── Demo
├── Images
│ ├── PKNotification.gif
│ └── PKNotification.png
├── Demo.xcodeproj
│ ├── project.xcworkspace
│ │ └── contents.xcworkspacedata
│ └── project.pbxproj
└── Demo
│ ├── Assets.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
│ ├── Info.plist
│ ├── AppDelegate.swift
│ ├── Base.lproj
│ ├── LaunchScreen.storyboard
│ └── Main.storyboard
│ └── ViewController.swift
├── PKNotification.xcodeproj
├── project.xcworkspace
│ └── contents.xcworkspacedata
├── xcshareddata
│ └── xcschemes
│ │ └── PKNotification.xcscheme
└── project.pbxproj
├── .gitignore
├── PKNotification
├── PKNotification.h
├── Info.plist
└── PKNotification.swift
├── LICENSE
├── README.md
└── PKNotification.podspec
/Demo/Images/PKNotification.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hakopako/PKNotification/HEAD/Demo/Images/PKNotification.gif
--------------------------------------------------------------------------------
/Demo/Images/PKNotification.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hakopako/PKNotification/HEAD/Demo/Images/PKNotification.png
--------------------------------------------------------------------------------
/Demo/Demo.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/PKNotification.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # .gitignore
2 | #*.xcodeproj/*
3 | !*.xcodeproj/project.pbxproj
4 | !*.xcodeproj/project.xcworkspace/*
5 | !*.xcodeproj/xcshareddata/*
6 | !*.xcodeproj/default.*
7 | *.xcworkspace/*
8 | !*.xcworkspace/contents.xcworkspacedata
9 | !*.xcworkspace/xcshareddata/*
10 |
11 | Carthage/Build
12 |
13 |
--------------------------------------------------------------------------------
/PKNotification/PKNotification.h:
--------------------------------------------------------------------------------
1 | //
2 | // PKNotification.h
3 | // PKNotification
4 | //
5 | // Created by shimada on 2016/01/10.
6 | // Copyright © 2016年 hakopako. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | //! Project version number for PKNotification.
12 | FOUNDATION_EXPORT double PKNotificationVersionNumber;
13 |
14 | //! Project version string for PKNotification.
15 | FOUNDATION_EXPORT const unsigned char PKNotificationVersionString[];
16 |
17 | // In this header, you should import all the public headers of your framework using statements like #import
18 |
19 |
20 |
--------------------------------------------------------------------------------
/PKNotification/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | $(CURRENT_PROJECT_VERSION)
23 | NSPrincipalClass
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 hakopako
4 |
5 | ereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including withoutPermission isimitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Demo/Demo/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "ipad",
35 | "size" : "29x29",
36 | "scale" : "1x"
37 | },
38 | {
39 | "idiom" : "ipad",
40 | "size" : "29x29",
41 | "scale" : "2x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "40x40",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "40x40",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "76x76",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "76x76",
61 | "scale" : "2x"
62 | }
63 | ],
64 | "info" : {
65 | "version" : 1,
66 | "author" : "xcode"
67 | }
68 | }
--------------------------------------------------------------------------------
/Demo/Demo/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 | UISupportedInterfaceOrientations~ipad
40 |
41 | UIInterfaceOrientationPortrait
42 | UIInterfaceOrientationPortraitUpsideDown
43 | UIInterfaceOrientationLandscapeLeft
44 | UIInterfaceOrientationLandscapeRight
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | PKNotification
4 | ==============
5 | Simple and customizable notification functions in Swift.
6 |
7 | - Alert
8 | - ActionSheet
9 | - Toast
10 | - Loading
11 | - Success
12 | - Failed
13 |
14 | Feel free to send me your feedback and PR.
15 |
16 | # UI
17 |
18 |
19 |
20 | # How to use
21 |
22 | ## Manually
23 | Add `PKNotification/PKNotification.swift` into your project.
24 |
25 |
26 | ## Carthage
27 | `github "hakopako/PKNotification"`
28 |
29 |
30 | ## CocoaPods
31 | ```
32 | platform :ios, '8.0'
33 | use_frameworks!
34 | pod 'PKNotification', '~> 1.0'
35 | ```
36 |
37 | There is a global variable named `PKNotification`. Use the variable and call methods.
38 | For more details, see [http://hakopako.github.io/PKNotification/](http://hakopako.github.io/PKNotification/)
39 |
40 |
41 | # History
42 |
43 | ### v1.0
44 |
45 | - update to Xcode7.x
46 | - update target to iOS8 or later
47 | - add actionsheet function.
48 | - adapt to CocoaPods and Carthage.
49 |
50 | ### v0.2.0
51 | - fixed alert with textfield
52 | - will be added default images (not yet..
53 |
54 | ### v0.1.1
55 | - fixed error with Xcode6.3
56 |
57 | ### v0.1.0
58 | - fixed device rotate for ios8
59 | - able to add UITextField on Alert
60 | - fixed dismiss action of alert.
61 |
62 | ### v0.0.3
63 | - fix architecture to customize UI easier
64 |
65 | ### v0.0.1
66 | - Toast message
67 | - Progress(Success, Failed, Loading)
68 |
69 |
--------------------------------------------------------------------------------
/Demo/Demo/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // Demo
4 | //
5 | // Created by shimada on 2016/01/10.
6 | // Copyright © 2016年 hakopako. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | @UIApplicationMain
12 | class AppDelegate: UIResponder, UIApplicationDelegate {
13 |
14 | var window: UIWindow?
15 |
16 |
17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
18 | // Override point for customization after application launch.
19 | return true
20 | }
21 |
22 | func applicationWillResignActive(application: UIApplication) {
23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
25 | }
26 |
27 | func applicationDidEnterBackground(application: UIApplication) {
28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30 | }
31 |
32 | func applicationWillEnterForeground(application: UIApplication) {
33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
34 | }
35 |
36 | func applicationDidBecomeActive(application: UIApplication) {
37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
38 | }
39 |
40 | func applicationWillTerminate(application: UIApplication) {
41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42 | }
43 |
44 |
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/PKNotification.xcodeproj/xcshareddata/xcschemes/PKNotification.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
34 |
35 |
45 |
46 |
52 |
53 |
54 |
55 |
56 |
57 |
63 |
64 |
70 |
71 |
72 |
73 |
75 |
76 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/Demo/Demo/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/PKNotification.podspec:
--------------------------------------------------------------------------------
1 | #
2 | # Be sure to run `pod spec lint PKNotification.podspec' to ensure this is a
3 | # valid spec and to remove all comments including this before submitting the spec.
4 | #
5 | # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
7 | #
8 |
9 | Pod::Spec.new do |s|
10 |
11 | # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
12 | #
13 | # These will help people to find your library, and whilst it
14 | # can feel like a chore to fill in it's definitely to your advantage. The
15 | # summary should be tweet-length, and the description more in depth.
16 | #
17 |
18 | s.name = "PKNotification"
19 | s.version = "1.0"
20 | s.summary = "Simple and customizable notifications in Swift."
21 |
22 | # This description is used to generate tags and improve search results.
23 | # * Think: What does it do? Why did you write it? What is the focus?
24 | # * Try to keep it short, snappy and to the point.
25 | # * Write the description between the DESC delimiters below.
26 | # * Finally, don't worry about the indent, CocoaPods strips it!
27 | s.description = <<-DESC
28 | - Simple and customizable notifications in Swift.
29 | DESC
30 |
31 | s.homepage = "http://hakopako.github.io/PKNotification/"
32 | # s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"
33 |
34 |
35 | # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
36 | #
37 | # Licensing your code is important. See http://choosealicense.com for more info.
38 | # CocoaPods will detect a license file if there is a named LICENSE*
39 | # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
40 | #
41 |
42 | s.license = "MIT"
43 | # s.license = { :type => "MIT", :file => "FILE_LICENSE" }
44 |
45 |
46 | # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
47 | #
48 | # Specify the authors of the library, with email addresses. Email addresses
49 | # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
50 | # accepts just a name if you'd rather not provide an email address.
51 | #
52 | # Specify a social_media_url where others can refer to, for example a twitter
53 | # profile URL.
54 | #
55 |
56 | s.author = { "shi-man" => "hakohakohako.0518@gmail.com" }
57 | # Or just: s.author = "shi-man"
58 | # s.authors = { "shi-man" => "hakohakohako.0518@gmail.com" }
59 | # s.social_media_url = "http://twitter.com/shi-man"
60 |
61 | # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
62 | #
63 | # If this Pod runs only on iOS or OS X, then specify the platform and
64 | # the deployment target. You can optionally include the target after the platform.
65 | #
66 |
67 | # s.platform = :ios
68 | s.platform = :ios, "8.0"
69 |
70 | # When using multiple platforms
71 | # s.ios.deployment_target = "5.0"
72 | # s.osx.deployment_target = "10.7"
73 | # s.watchos.deployment_target = "2.0"
74 | # s.tvos.deployment_target = "9.0"
75 |
76 |
77 | # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
78 | #
79 | # Specify the location from where the source should be retrieved.
80 | # Supports git, hg, bzr, svn and HTTP.
81 | #
82 |
83 | s.source = { :git => "https://github.com/hakopako/PKNotification.git", :tag => "v1.0" }
84 |
85 |
86 | # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
87 | #
88 | # CocoaPods is smart about how it includes source code. For source files
89 | # giving a folder will include any swift, h, m, mm, c & cpp files.
90 | # For header files it will include any header in the folder.
91 | # Not including the public_header_files will make all headers public.
92 | #
93 |
94 | s.source_files = "PKNotification/**/*.swift"
95 | # s.exclude_files = "Classes/Exclude"
96 | # s.public_header_files = "Classes/**/*.h"
97 |
98 |
99 | # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
100 | #
101 | # A list of resources included with the Pod. These are copied into the
102 | # target bundle with a build phase script. Anything else will be cleaned.
103 | # You can preserve files from being cleaned, please don't preserve
104 | # non-essential files like tests, examples and documentation.
105 | #
106 |
107 | # s.resource = "icon.png"
108 | # s.resources = "Resources/*.png"
109 |
110 | # s.preserve_paths = "FilesToSave", "MoreFilesToSave"
111 |
112 |
113 | # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
114 | #
115 | # Link your library with frameworks, or libraries. Libraries do not include
116 | # the lib prefix of their name.
117 | #
118 |
119 | # s.framework = "SomeFramework"
120 | # s.frameworks = "SomeFramework", "AnotherFramework"
121 |
122 | # s.library = "iconv"
123 | # s.libraries = "iconv", "xml2"
124 |
125 |
126 | # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
127 | #
128 | # If your library depends on compiler flags you can set them in the xcconfig hash
129 | # where they will only apply to your library. If you depend on other Podspecs
130 | # you can include multiple dependencies to ensure it works.
131 |
132 | # s.requires_arc = true
133 |
134 | # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
135 | # s.dependency "JSONKit", "~> 1.4"
136 |
137 | end
138 |
--------------------------------------------------------------------------------
/Demo/Demo/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // PKNotification
4 | //
5 | // Created by hakopako on 2014/12/24.
6 | // Copyright (c) 2014年 hakopako. All rights reserved.
7 | //
8 |
9 |
10 | import UIKit
11 |
12 | class ViewController: UIViewController {
13 |
14 | @IBOutlet weak var alertButton: UIButton!
15 | @IBOutlet weak var alertButtonOptions: UIButton!
16 | @IBOutlet weak var alertWithTextField: UIButton!
17 | @IBOutlet weak var actionsheetButton: UIButton!
18 | @IBOutlet weak var toastButton: UIButton!
19 | @IBOutlet weak var loadingButton: UIButton!
20 | @IBOutlet weak var successButton: UIButton!
21 | @IBOutlet weak var failedButton: UIButton!
22 |
23 | override func viewDidLoad() {
24 | super.viewDidLoad()
25 | PKNotification.alertCornerRadius = 3
26 | }
27 |
28 | override func viewDidAppear(animated: Bool) {
29 | super.viewDidAppear(animated)
30 | }
31 |
32 | override func didReceiveMemoryWarning() {
33 | super.didReceiveMemoryWarning()
34 | }
35 | @IBAction func alertButtonDown(sender: AnyObject) {
36 | PKNotification.alert(
37 | title: "Success !!",
38 | message: "Foooooooooooooo\nDisplay this default style pop up view.\nBaaaaaar",
39 | items: nil,
40 | cancelButtonTitle: "O K",
41 | tintColor: nil)
42 |
43 | }
44 |
45 | @IBAction func alertButtonOptionsDown(sender: AnyObject) {
46 | let foo:PKButton = PKButton(title: "Foo",
47 | action: { (messageLabel, items) -> Bool in
48 | NSLog("Foo is clicked.")
49 | return true
50 | },
51 | fontColor: UIColor.purpleColor(),
52 | backgroundColor: nil)
53 |
54 | let bar:PKButton = PKButton(title: "Not Dismiss",
55 | action: { (messageLabel, items) -> Bool in
56 | NSLog("Not Dismiss is clicked.")
57 | messageLabel?.text = "not dismiss button is clicked."
58 | return false
59 | },
60 | fontColor: nil,
61 | backgroundColor: nil)
62 | PKNotification.alert(
63 | title: "Notice",
64 | message: "Foooooooooooooo\nDisplay this default style pop up view.\nBaaaaaar",
65 | items: [foo, bar],
66 | cancelButtonTitle: "Cancel",
67 | tintColor: nil)
68 | }
69 |
70 | @IBAction func alertWithTextFieldDown(sender: AnyObject) {
71 |
72 | let email:UITextField = UITextField()
73 | email.placeholder = "email@host.com"
74 | email.backgroundColor = UIColor(red: 0.95, green: 0.96, blue: 1.0, alpha: 1.0)
75 | email.textColor = UIColor.darkGrayColor()
76 |
77 |
78 | let passwd:UITextField = UITextField()
79 | passwd.placeholder = "password"
80 | passwd.backgroundColor = UIColor(red: 0.95, green: 0.96, blue: 1.0, alpha: 1.0)
81 | passwd.textColor = UIColor.darkGrayColor()
82 |
83 | let foo:PKButton = PKButton(title: "Login",
84 | action: { (messageLabel, items) -> Bool in
85 | NSLog("Login is clicked.")
86 | let tmpEmail: UITextField = items[0] as! UITextField //items index number
87 | let tmpPassed: UITextField = items[1] as! UITextField //items index number
88 | NSLog("email = \(tmpEmail.text)")
89 | NSLog("passwd = \(tmpPassed.text)")
90 |
91 | if (tmpEmail.text == "" || tmpPassed.text == ""){
92 | messageLabel?.text = "please check email and password again."
93 | tmpEmail.backgroundColor = UIColor(red: 0.95, green: 0.8, blue: 0.8, alpha: 1.0)
94 | tmpPassed.backgroundColor = UIColor(red: 0.95, green: 0.8, blue: 0.8, alpha: 1.0)
95 | return false
96 | }
97 | return true
98 | },
99 | fontColor: UIColor(red: 0, green: 0.55, blue: 0.9, alpha: 1.0),
100 | backgroundColor: nil)
101 |
102 |
103 | PKNotification.alert(
104 | title: "Login",
105 | message: "Welcome to example.\nThis is a simple login form.",
106 | items: [email, passwd, foo],
107 | cancelButtonTitle: "Cancel",
108 | tintColor: nil)
109 |
110 | }
111 |
112 | @IBAction func actionsheetButtonDown(sender: AnyObject) {
113 | PKNotification.actionSheetCornerRadius = 3
114 | let foo:PKButton = PKButton(title: "Foo",
115 | action: { (m, i) -> Bool in
116 | NSLog("Foo is clicked.")
117 | return true
118 | },
119 | fontColor: UIColor(red: 0, green: 0.55, blue: 0.9, alpha: 1.0),
120 | backgroundColor: nil)
121 | let bar:PKButton = PKButton(title: "Bar",
122 | action: { (m, i) -> Bool in
123 | NSLog("Bar is clicked.")
124 | return true
125 | },
126 | fontColor: UIColor.purpleColor(),
127 | backgroundColor: nil)
128 | PKNotification.actionSheet(
129 | title: "Title",
130 | items: [foo, bar],
131 | cancelButtonTitle: "Cancel",
132 | tintColor: nil)
133 | }
134 |
135 | @IBAction func toastButtonDown(sender: AnyObject) {
136 | PKNotification.toastBackgroundColor = UIColor.purpleColor()
137 | PKNotification.toast("hogehogehogehoge")
138 | }
139 |
140 | @IBAction func loadingButtonDown(sender: AnyObject) {
141 | PKNotification.loading(true)
142 | NSLog("start loading...")
143 | NSTimer.scheduledTimerWithTimeInterval(2.0, target: self, selector:"onUpdate:", userInfo: nil, repeats: false)
144 | }
145 |
146 | func onUpdate(timer: NSTimer) {
147 | NSLog("finish loading...")
148 | PKNotification.loading(false)
149 | }
150 |
151 | @IBAction func successButtonDown(sender: AnyObject) {
152 | PKNotification.successBackgroundColor = UIColor(red: 0, green: 0.55, blue: 0.9, alpha: 1.0)
153 | PKNotification.success(nil)
154 | }
155 |
156 | @IBAction func failedButtonDown(sender: AnyObject) {
157 | PKNotification.failed("Failed ...")
158 | }
159 |
160 | }
161 |
162 |
--------------------------------------------------------------------------------
/PKNotification.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | D20AE7EA1C41FFEF00237004 /* PKNotification.h in Headers */ = {isa = PBXBuildFile; fileRef = D20AE7E91C41FFEF00237004 /* PKNotification.h */; settings = {ATTRIBUTES = (Public, ); }; };
11 | D20AE7F41C42009B00237004 /* PKNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20AE7F31C42009B00237004 /* PKNotification.swift */; };
12 | /* End PBXBuildFile section */
13 |
14 | /* Begin PBXFileReference section */
15 | D20AE7E61C41FFEF00237004 /* PKNotification.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PKNotification.framework; sourceTree = BUILT_PRODUCTS_DIR; };
16 | D20AE7E91C41FFEF00237004 /* PKNotification.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PKNotification.h; sourceTree = ""; };
17 | D20AE7EB1C41FFEF00237004 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
18 | D20AE7F31C42009B00237004 /* PKNotification.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKNotification.swift; sourceTree = ""; };
19 | /* End PBXFileReference section */
20 |
21 | /* Begin PBXFrameworksBuildPhase section */
22 | D20AE7E21C41FFEF00237004 /* Frameworks */ = {
23 | isa = PBXFrameworksBuildPhase;
24 | buildActionMask = 2147483647;
25 | files = (
26 | );
27 | runOnlyForDeploymentPostprocessing = 0;
28 | };
29 | /* End PBXFrameworksBuildPhase section */
30 |
31 | /* Begin PBXGroup section */
32 | D20AE7DC1C41FFEF00237004 = {
33 | isa = PBXGroup;
34 | children = (
35 | D20AE7E81C41FFEF00237004 /* PKNotification */,
36 | D20AE7E71C41FFEF00237004 /* Products */,
37 | );
38 | sourceTree = "";
39 | };
40 | D20AE7E71C41FFEF00237004 /* Products */ = {
41 | isa = PBXGroup;
42 | children = (
43 | D20AE7E61C41FFEF00237004 /* PKNotification.framework */,
44 | );
45 | name = Products;
46 | sourceTree = "";
47 | };
48 | D20AE7E81C41FFEF00237004 /* PKNotification */ = {
49 | isa = PBXGroup;
50 | children = (
51 | D20AE7F31C42009B00237004 /* PKNotification.swift */,
52 | D20AE7E91C41FFEF00237004 /* PKNotification.h */,
53 | D20AE7EB1C41FFEF00237004 /* Info.plist */,
54 | );
55 | path = PKNotification;
56 | sourceTree = "";
57 | };
58 | /* End PBXGroup section */
59 |
60 | /* Begin PBXHeadersBuildPhase section */
61 | D20AE7E31C41FFEF00237004 /* Headers */ = {
62 | isa = PBXHeadersBuildPhase;
63 | buildActionMask = 2147483647;
64 | files = (
65 | D20AE7EA1C41FFEF00237004 /* PKNotification.h in Headers */,
66 | );
67 | runOnlyForDeploymentPostprocessing = 0;
68 | };
69 | /* End PBXHeadersBuildPhase section */
70 |
71 | /* Begin PBXNativeTarget section */
72 | D20AE7E51C41FFEF00237004 /* PKNotification */ = {
73 | isa = PBXNativeTarget;
74 | buildConfigurationList = D20AE7EE1C41FFEF00237004 /* Build configuration list for PBXNativeTarget "PKNotification" */;
75 | buildPhases = (
76 | D20AE7E11C41FFEF00237004 /* Sources */,
77 | D20AE7E21C41FFEF00237004 /* Frameworks */,
78 | D20AE7E31C41FFEF00237004 /* Headers */,
79 | D20AE7E41C41FFEF00237004 /* Resources */,
80 | );
81 | buildRules = (
82 | );
83 | dependencies = (
84 | );
85 | name = PKNotification;
86 | productName = PKNotification;
87 | productReference = D20AE7E61C41FFEF00237004 /* PKNotification.framework */;
88 | productType = "com.apple.product-type.framework";
89 | };
90 | /* End PBXNativeTarget section */
91 |
92 | /* Begin PBXProject section */
93 | D20AE7DD1C41FFEF00237004 /* Project object */ = {
94 | isa = PBXProject;
95 | attributes = {
96 | LastUpgradeCheck = 0710;
97 | ORGANIZATIONNAME = hakopako;
98 | TargetAttributes = {
99 | D20AE7E51C41FFEF00237004 = {
100 | CreatedOnToolsVersion = 7.1;
101 | };
102 | };
103 | };
104 | buildConfigurationList = D20AE7E01C41FFEF00237004 /* Build configuration list for PBXProject "PKNotification" */;
105 | compatibilityVersion = "Xcode 3.2";
106 | developmentRegion = English;
107 | hasScannedForEncodings = 0;
108 | knownRegions = (
109 | en,
110 | );
111 | mainGroup = D20AE7DC1C41FFEF00237004;
112 | productRefGroup = D20AE7E71C41FFEF00237004 /* Products */;
113 | projectDirPath = "";
114 | projectRoot = "";
115 | targets = (
116 | D20AE7E51C41FFEF00237004 /* PKNotification */,
117 | );
118 | };
119 | /* End PBXProject section */
120 |
121 | /* Begin PBXResourcesBuildPhase section */
122 | D20AE7E41C41FFEF00237004 /* Resources */ = {
123 | isa = PBXResourcesBuildPhase;
124 | buildActionMask = 2147483647;
125 | files = (
126 | );
127 | runOnlyForDeploymentPostprocessing = 0;
128 | };
129 | /* End PBXResourcesBuildPhase section */
130 |
131 | /* Begin PBXSourcesBuildPhase section */
132 | D20AE7E11C41FFEF00237004 /* Sources */ = {
133 | isa = PBXSourcesBuildPhase;
134 | buildActionMask = 2147483647;
135 | files = (
136 | D20AE7F41C42009B00237004 /* PKNotification.swift in Sources */,
137 | );
138 | runOnlyForDeploymentPostprocessing = 0;
139 | };
140 | /* End PBXSourcesBuildPhase section */
141 |
142 | /* Begin XCBuildConfiguration section */
143 | D20AE7EC1C41FFEF00237004 /* Debug */ = {
144 | isa = XCBuildConfiguration;
145 | buildSettings = {
146 | ALWAYS_SEARCH_USER_PATHS = NO;
147 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
148 | CLANG_CXX_LIBRARY = "libc++";
149 | CLANG_ENABLE_MODULES = YES;
150 | CLANG_ENABLE_OBJC_ARC = YES;
151 | CLANG_WARN_BOOL_CONVERSION = YES;
152 | CLANG_WARN_CONSTANT_CONVERSION = YES;
153 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
154 | CLANG_WARN_EMPTY_BODY = YES;
155 | CLANG_WARN_ENUM_CONVERSION = YES;
156 | CLANG_WARN_INT_CONVERSION = YES;
157 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
158 | CLANG_WARN_UNREACHABLE_CODE = YES;
159 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
160 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
161 | COPY_PHASE_STRIP = NO;
162 | CURRENT_PROJECT_VERSION = 1;
163 | DEBUG_INFORMATION_FORMAT = dwarf;
164 | ENABLE_STRICT_OBJC_MSGSEND = YES;
165 | ENABLE_TESTABILITY = YES;
166 | GCC_C_LANGUAGE_STANDARD = gnu99;
167 | GCC_DYNAMIC_NO_PIC = NO;
168 | GCC_NO_COMMON_BLOCKS = YES;
169 | GCC_OPTIMIZATION_LEVEL = 0;
170 | GCC_PREPROCESSOR_DEFINITIONS = (
171 | "DEBUG=1",
172 | "$(inherited)",
173 | );
174 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
175 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
176 | GCC_WARN_UNDECLARED_SELECTOR = YES;
177 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
178 | GCC_WARN_UNUSED_FUNCTION = YES;
179 | GCC_WARN_UNUSED_VARIABLE = YES;
180 | IPHONEOS_DEPLOYMENT_TARGET = 9.1;
181 | MTL_ENABLE_DEBUG_INFO = YES;
182 | ONLY_ACTIVE_ARCH = YES;
183 | SDKROOT = iphoneos;
184 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
185 | TARGETED_DEVICE_FAMILY = "1,2";
186 | VERSIONING_SYSTEM = "apple-generic";
187 | VERSION_INFO_PREFIX = "";
188 | };
189 | name = Debug;
190 | };
191 | D20AE7ED1C41FFEF00237004 /* Release */ = {
192 | isa = XCBuildConfiguration;
193 | buildSettings = {
194 | ALWAYS_SEARCH_USER_PATHS = NO;
195 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
196 | CLANG_CXX_LIBRARY = "libc++";
197 | CLANG_ENABLE_MODULES = YES;
198 | CLANG_ENABLE_OBJC_ARC = YES;
199 | CLANG_WARN_BOOL_CONVERSION = YES;
200 | CLANG_WARN_CONSTANT_CONVERSION = YES;
201 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
202 | CLANG_WARN_EMPTY_BODY = YES;
203 | CLANG_WARN_ENUM_CONVERSION = YES;
204 | CLANG_WARN_INT_CONVERSION = YES;
205 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
206 | CLANG_WARN_UNREACHABLE_CODE = YES;
207 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
208 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
209 | COPY_PHASE_STRIP = NO;
210 | CURRENT_PROJECT_VERSION = 1;
211 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
212 | ENABLE_NS_ASSERTIONS = NO;
213 | ENABLE_STRICT_OBJC_MSGSEND = YES;
214 | GCC_C_LANGUAGE_STANDARD = gnu99;
215 | GCC_NO_COMMON_BLOCKS = YES;
216 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
217 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
218 | GCC_WARN_UNDECLARED_SELECTOR = YES;
219 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
220 | GCC_WARN_UNUSED_FUNCTION = YES;
221 | GCC_WARN_UNUSED_VARIABLE = YES;
222 | IPHONEOS_DEPLOYMENT_TARGET = 9.1;
223 | MTL_ENABLE_DEBUG_INFO = NO;
224 | SDKROOT = iphoneos;
225 | TARGETED_DEVICE_FAMILY = "1,2";
226 | VALIDATE_PRODUCT = YES;
227 | VERSIONING_SYSTEM = "apple-generic";
228 | VERSION_INFO_PREFIX = "";
229 | };
230 | name = Release;
231 | };
232 | D20AE7EF1C41FFEF00237004 /* Debug */ = {
233 | isa = XCBuildConfiguration;
234 | buildSettings = {
235 | CLANG_ENABLE_MODULES = YES;
236 | DEFINES_MODULE = YES;
237 | DYLIB_COMPATIBILITY_VERSION = 1;
238 | DYLIB_CURRENT_VERSION = 1;
239 | DYLIB_INSTALL_NAME_BASE = "@rpath";
240 | INFOPLIST_FILE = PKNotification/Info.plist;
241 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
242 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
243 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
244 | PRODUCT_BUNDLE_IDENTIFIER = com.hakopako.PKNotification;
245 | PRODUCT_NAME = "$(TARGET_NAME)";
246 | SKIP_INSTALL = YES;
247 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
248 | };
249 | name = Debug;
250 | };
251 | D20AE7F01C41FFEF00237004 /* Release */ = {
252 | isa = XCBuildConfiguration;
253 | buildSettings = {
254 | CLANG_ENABLE_MODULES = YES;
255 | DEFINES_MODULE = YES;
256 | DYLIB_COMPATIBILITY_VERSION = 1;
257 | DYLIB_CURRENT_VERSION = 1;
258 | DYLIB_INSTALL_NAME_BASE = "@rpath";
259 | INFOPLIST_FILE = PKNotification/Info.plist;
260 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
261 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
262 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
263 | PRODUCT_BUNDLE_IDENTIFIER = com.hakopako.PKNotification;
264 | PRODUCT_NAME = "$(TARGET_NAME)";
265 | SKIP_INSTALL = YES;
266 | };
267 | name = Release;
268 | };
269 | /* End XCBuildConfiguration section */
270 |
271 | /* Begin XCConfigurationList section */
272 | D20AE7E01C41FFEF00237004 /* Build configuration list for PBXProject "PKNotification" */ = {
273 | isa = XCConfigurationList;
274 | buildConfigurations = (
275 | D20AE7EC1C41FFEF00237004 /* Debug */,
276 | D20AE7ED1C41FFEF00237004 /* Release */,
277 | );
278 | defaultConfigurationIsVisible = 0;
279 | defaultConfigurationName = Release;
280 | };
281 | D20AE7EE1C41FFEF00237004 /* Build configuration list for PBXNativeTarget "PKNotification" */ = {
282 | isa = XCConfigurationList;
283 | buildConfigurations = (
284 | D20AE7EF1C41FFEF00237004 /* Debug */,
285 | D20AE7F01C41FFEF00237004 /* Release */,
286 | );
287 | defaultConfigurationIsVisible = 0;
288 | defaultConfigurationName = Release;
289 | };
290 | /* End XCConfigurationList section */
291 | };
292 | rootObject = D20AE7DD1C41FFEF00237004 /* Project object */;
293 | }
294 |
--------------------------------------------------------------------------------
/Demo/Demo.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | D20AE8021C42010B00237004 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20AE8011C42010B00237004 /* AppDelegate.swift */; };
11 | D20AE8041C42010B00237004 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20AE8031C42010B00237004 /* ViewController.swift */; };
12 | D20AE8071C42010B00237004 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D20AE8051C42010B00237004 /* Main.storyboard */; };
13 | D20AE8091C42010B00237004 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D20AE8081C42010B00237004 /* Assets.xcassets */; };
14 | D20AE80C1C42010B00237004 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D20AE80A1C42010B00237004 /* LaunchScreen.storyboard */; };
15 | D20AE8141C4201E400237004 /* PKNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20AE8131C4201E400237004 /* PKNotification.swift */; };
16 | /* End PBXBuildFile section */
17 |
18 | /* Begin PBXFileReference section */
19 | D20AE7FE1C42010B00237004 /* Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Demo.app; sourceTree = BUILT_PRODUCTS_DIR; };
20 | D20AE8011C42010B00237004 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; };
21 | D20AE8031C42010B00237004 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; };
22 | D20AE8061C42010B00237004 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
23 | D20AE8081C42010B00237004 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
24 | D20AE80B1C42010B00237004 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
25 | D20AE80D1C42010B00237004 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
26 | D20AE8131C4201E400237004 /* PKNotification.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PKNotification.swift; path = ../../PKNotification/PKNotification.swift; sourceTree = ""; };
27 | /* End PBXFileReference section */
28 |
29 | /* Begin PBXFrameworksBuildPhase section */
30 | D20AE7FB1C42010B00237004 /* Frameworks */ = {
31 | isa = PBXFrameworksBuildPhase;
32 | buildActionMask = 2147483647;
33 | files = (
34 | );
35 | runOnlyForDeploymentPostprocessing = 0;
36 | };
37 | /* End PBXFrameworksBuildPhase section */
38 |
39 | /* Begin PBXGroup section */
40 | D20AE7F51C42010B00237004 = {
41 | isa = PBXGroup;
42 | children = (
43 | D20AE8001C42010B00237004 /* Demo */,
44 | D20AE7FF1C42010B00237004 /* Products */,
45 | );
46 | sourceTree = "";
47 | };
48 | D20AE7FF1C42010B00237004 /* Products */ = {
49 | isa = PBXGroup;
50 | children = (
51 | D20AE7FE1C42010B00237004 /* Demo.app */,
52 | );
53 | name = Products;
54 | sourceTree = "";
55 | };
56 | D20AE8001C42010B00237004 /* Demo */ = {
57 | isa = PBXGroup;
58 | children = (
59 | D20AE8131C4201E400237004 /* PKNotification.swift */,
60 | D20AE8011C42010B00237004 /* AppDelegate.swift */,
61 | D20AE8031C42010B00237004 /* ViewController.swift */,
62 | D20AE8051C42010B00237004 /* Main.storyboard */,
63 | D20AE8081C42010B00237004 /* Assets.xcassets */,
64 | D20AE80A1C42010B00237004 /* LaunchScreen.storyboard */,
65 | D20AE80D1C42010B00237004 /* Info.plist */,
66 | );
67 | path = Demo;
68 | sourceTree = "";
69 | };
70 | /* End PBXGroup section */
71 |
72 | /* Begin PBXNativeTarget section */
73 | D20AE7FD1C42010B00237004 /* Demo */ = {
74 | isa = PBXNativeTarget;
75 | buildConfigurationList = D20AE8101C42010B00237004 /* Build configuration list for PBXNativeTarget "Demo" */;
76 | buildPhases = (
77 | D20AE7FA1C42010B00237004 /* Sources */,
78 | D20AE7FB1C42010B00237004 /* Frameworks */,
79 | D20AE7FC1C42010B00237004 /* Resources */,
80 | );
81 | buildRules = (
82 | );
83 | dependencies = (
84 | );
85 | name = Demo;
86 | productName = Demo;
87 | productReference = D20AE7FE1C42010B00237004 /* Demo.app */;
88 | productType = "com.apple.product-type.application";
89 | };
90 | /* End PBXNativeTarget section */
91 |
92 | /* Begin PBXProject section */
93 | D20AE7F61C42010B00237004 /* Project object */ = {
94 | isa = PBXProject;
95 | attributes = {
96 | LastSwiftUpdateCheck = 0710;
97 | LastUpgradeCheck = 0710;
98 | ORGANIZATIONNAME = hakopako;
99 | TargetAttributes = {
100 | D20AE7FD1C42010B00237004 = {
101 | CreatedOnToolsVersion = 7.1;
102 | };
103 | };
104 | };
105 | buildConfigurationList = D20AE7F91C42010B00237004 /* Build configuration list for PBXProject "Demo" */;
106 | compatibilityVersion = "Xcode 3.2";
107 | developmentRegion = English;
108 | hasScannedForEncodings = 0;
109 | knownRegions = (
110 | en,
111 | Base,
112 | );
113 | mainGroup = D20AE7F51C42010B00237004;
114 | productRefGroup = D20AE7FF1C42010B00237004 /* Products */;
115 | projectDirPath = "";
116 | projectRoot = "";
117 | targets = (
118 | D20AE7FD1C42010B00237004 /* Demo */,
119 | );
120 | };
121 | /* End PBXProject section */
122 |
123 | /* Begin PBXResourcesBuildPhase section */
124 | D20AE7FC1C42010B00237004 /* Resources */ = {
125 | isa = PBXResourcesBuildPhase;
126 | buildActionMask = 2147483647;
127 | files = (
128 | D20AE80C1C42010B00237004 /* LaunchScreen.storyboard in Resources */,
129 | D20AE8091C42010B00237004 /* Assets.xcassets in Resources */,
130 | D20AE8071C42010B00237004 /* Main.storyboard in Resources */,
131 | );
132 | runOnlyForDeploymentPostprocessing = 0;
133 | };
134 | /* End PBXResourcesBuildPhase section */
135 |
136 | /* Begin PBXSourcesBuildPhase section */
137 | D20AE7FA1C42010B00237004 /* Sources */ = {
138 | isa = PBXSourcesBuildPhase;
139 | buildActionMask = 2147483647;
140 | files = (
141 | D20AE8041C42010B00237004 /* ViewController.swift in Sources */,
142 | D20AE8021C42010B00237004 /* AppDelegate.swift in Sources */,
143 | D20AE8141C4201E400237004 /* PKNotification.swift in Sources */,
144 | );
145 | runOnlyForDeploymentPostprocessing = 0;
146 | };
147 | /* End PBXSourcesBuildPhase section */
148 |
149 | /* Begin PBXVariantGroup section */
150 | D20AE8051C42010B00237004 /* Main.storyboard */ = {
151 | isa = PBXVariantGroup;
152 | children = (
153 | D20AE8061C42010B00237004 /* Base */,
154 | );
155 | name = Main.storyboard;
156 | sourceTree = "";
157 | };
158 | D20AE80A1C42010B00237004 /* LaunchScreen.storyboard */ = {
159 | isa = PBXVariantGroup;
160 | children = (
161 | D20AE80B1C42010B00237004 /* Base */,
162 | );
163 | name = LaunchScreen.storyboard;
164 | sourceTree = "";
165 | };
166 | /* End PBXVariantGroup section */
167 |
168 | /* Begin XCBuildConfiguration section */
169 | D20AE80E1C42010B00237004 /* Debug */ = {
170 | isa = XCBuildConfiguration;
171 | buildSettings = {
172 | ALWAYS_SEARCH_USER_PATHS = NO;
173 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
174 | CLANG_CXX_LIBRARY = "libc++";
175 | CLANG_ENABLE_MODULES = YES;
176 | CLANG_ENABLE_OBJC_ARC = YES;
177 | CLANG_WARN_BOOL_CONVERSION = YES;
178 | CLANG_WARN_CONSTANT_CONVERSION = YES;
179 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
180 | CLANG_WARN_EMPTY_BODY = YES;
181 | CLANG_WARN_ENUM_CONVERSION = YES;
182 | CLANG_WARN_INT_CONVERSION = YES;
183 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
184 | CLANG_WARN_UNREACHABLE_CODE = YES;
185 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
186 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
187 | COPY_PHASE_STRIP = NO;
188 | DEBUG_INFORMATION_FORMAT = dwarf;
189 | ENABLE_STRICT_OBJC_MSGSEND = YES;
190 | ENABLE_TESTABILITY = YES;
191 | GCC_C_LANGUAGE_STANDARD = gnu99;
192 | GCC_DYNAMIC_NO_PIC = NO;
193 | GCC_NO_COMMON_BLOCKS = YES;
194 | GCC_OPTIMIZATION_LEVEL = 0;
195 | GCC_PREPROCESSOR_DEFINITIONS = (
196 | "DEBUG=1",
197 | "$(inherited)",
198 | );
199 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
200 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
201 | GCC_WARN_UNDECLARED_SELECTOR = YES;
202 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
203 | GCC_WARN_UNUSED_FUNCTION = YES;
204 | GCC_WARN_UNUSED_VARIABLE = YES;
205 | IPHONEOS_DEPLOYMENT_TARGET = 9.1;
206 | MTL_ENABLE_DEBUG_INFO = YES;
207 | ONLY_ACTIVE_ARCH = YES;
208 | SDKROOT = iphoneos;
209 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
210 | TARGETED_DEVICE_FAMILY = "1,2";
211 | };
212 | name = Debug;
213 | };
214 | D20AE80F1C42010B00237004 /* Release */ = {
215 | isa = XCBuildConfiguration;
216 | buildSettings = {
217 | ALWAYS_SEARCH_USER_PATHS = NO;
218 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
219 | CLANG_CXX_LIBRARY = "libc++";
220 | CLANG_ENABLE_MODULES = YES;
221 | CLANG_ENABLE_OBJC_ARC = YES;
222 | CLANG_WARN_BOOL_CONVERSION = YES;
223 | CLANG_WARN_CONSTANT_CONVERSION = YES;
224 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
225 | CLANG_WARN_EMPTY_BODY = YES;
226 | CLANG_WARN_ENUM_CONVERSION = YES;
227 | CLANG_WARN_INT_CONVERSION = YES;
228 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
229 | CLANG_WARN_UNREACHABLE_CODE = YES;
230 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
231 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
232 | COPY_PHASE_STRIP = NO;
233 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
234 | ENABLE_NS_ASSERTIONS = NO;
235 | ENABLE_STRICT_OBJC_MSGSEND = YES;
236 | GCC_C_LANGUAGE_STANDARD = gnu99;
237 | GCC_NO_COMMON_BLOCKS = YES;
238 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
239 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
240 | GCC_WARN_UNDECLARED_SELECTOR = YES;
241 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
242 | GCC_WARN_UNUSED_FUNCTION = YES;
243 | GCC_WARN_UNUSED_VARIABLE = YES;
244 | IPHONEOS_DEPLOYMENT_TARGET = 9.1;
245 | MTL_ENABLE_DEBUG_INFO = NO;
246 | SDKROOT = iphoneos;
247 | TARGETED_DEVICE_FAMILY = "1,2";
248 | VALIDATE_PRODUCT = YES;
249 | };
250 | name = Release;
251 | };
252 | D20AE8111C42010B00237004 /* Debug */ = {
253 | isa = XCBuildConfiguration;
254 | buildSettings = {
255 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
256 | INFOPLIST_FILE = Demo/Info.plist;
257 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
258 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
259 | PRODUCT_BUNDLE_IDENTIFIER = com.hakopako.Demo;
260 | PRODUCT_NAME = "$(TARGET_NAME)";
261 | };
262 | name = Debug;
263 | };
264 | D20AE8121C42010B00237004 /* Release */ = {
265 | isa = XCBuildConfiguration;
266 | buildSettings = {
267 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
268 | INFOPLIST_FILE = Demo/Info.plist;
269 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
270 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
271 | PRODUCT_BUNDLE_IDENTIFIER = com.hakopako.Demo;
272 | PRODUCT_NAME = "$(TARGET_NAME)";
273 | };
274 | name = Release;
275 | };
276 | /* End XCBuildConfiguration section */
277 |
278 | /* Begin XCConfigurationList section */
279 | D20AE7F91C42010B00237004 /* Build configuration list for PBXProject "Demo" */ = {
280 | isa = XCConfigurationList;
281 | buildConfigurations = (
282 | D20AE80E1C42010B00237004 /* Debug */,
283 | D20AE80F1C42010B00237004 /* Release */,
284 | );
285 | defaultConfigurationIsVisible = 0;
286 | defaultConfigurationName = Release;
287 | };
288 | D20AE8101C42010B00237004 /* Build configuration list for PBXNativeTarget "Demo" */ = {
289 | isa = XCConfigurationList;
290 | buildConfigurations = (
291 | D20AE8111C42010B00237004 /* Debug */,
292 | D20AE8121C42010B00237004 /* Release */,
293 | );
294 | defaultConfigurationIsVisible = 0;
295 | defaultConfigurationName = Release;
296 | };
297 | /* End XCConfigurationList section */
298 | };
299 | rootObject = D20AE7F61C42010B00237004 /* Project object */;
300 | }
301 |
--------------------------------------------------------------------------------
/Demo/Demo/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
36 |
50 |
64 |
78 |
92 |
106 |
120 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
--------------------------------------------------------------------------------
/PKNotification/PKNotification.swift:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | PKNotification.swift
3 | PKNotification
4 |
5 | Created by hakopako on 2014/12/24.
6 | Copyright (c) 2014 hakopako.
7 | Source:https://github.com/hakopako/PKNotification
8 |
9 | Permission is hereby granted, free of charge, to any person obtaining a
10 | copy of this software and associated documentation files (the
11 | "Software"), to deal in the Software without restriction, including
12 | without limitation the rights to use, copy, modify, merge, publish,
13 | distribute, sublicense, and/or sell copies of the Software, and to
14 | permit persons to whom the Software is furnished to do so, subject to
15 | the following conditions:
16 |
17 | The above copyright notice and this permission notice shall be included
18 | in all copies or substantial portions of the Software.
19 |
20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 |
28 | *********************************************************************/
29 |
30 | import UIKit
31 |
32 | typealias PKButtonActionBlock = (messageLabel:UILabel?, items:Array) -> Bool
33 | let _PKNotificationSingleton:PKNotificationSingleton = PKNotificationSingleton()
34 | let PKNotification:PKNotificationClass = PKNotificationClass()
35 |
36 | // MARK: - @CLASS PKNotificationSingleton
37 | class PKNotificationSingleton {
38 | var vcCollection:Array = Array()
39 | var isLoading:Bool = false
40 | }
41 |
42 | // MARK: - @CLASS PKNotification
43 | class PKNotificationClass: UIViewController {
44 |
45 | enum PKProgressType {
46 | case Loading, Success, Failed
47 | }
48 |
49 | let onVersion:Float = (UIDevice.currentDevice().systemVersion).floatValue
50 | let defaultSuccessImage:UIImage = Images().success()
51 | let defaultFailedImage:UIImage = Images().failed()
52 |
53 |
54 | //PKToast custom
55 | var toastMargin:CGFloat = 8
56 | var toastHeight:CGFloat = 50
57 | var toastAlpha:CGFloat = 0.8
58 | var toastRadious:CGFloat = 1
59 | var toastBackgroundColor:UIColor = UIColor.blackColor()
60 | var toastFontColor:UIColor = UIColor.whiteColor()
61 | var toastFontStyle:UIFont = UIFont.systemFontOfSize(15)
62 |
63 | //PKProgress custom
64 | var progressHeight:CGFloat = 110
65 | var progressWidth:CGFloat = 110
66 | var progressAlpha:CGFloat = 0.6
67 | var progressRadious:CGFloat = 12
68 | var progressLabelHeight:CGFloat = 40
69 | var progressFontColor:UIColor = UIColor.whiteColor()
70 | var progressFontStyle:UIFont = UIFont.boldSystemFontOfSize(14)
71 |
72 | //--- loading
73 | var loadingBackgroundColor:UIColor = UIColor.blackColor()
74 | var loadingActiveIndicatorStyle:UIActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.WhiteLarge
75 |
76 | //--- success
77 | var successBackgroundColor:UIColor = UIColor.blackColor()
78 | var successImage:UIImage? = nil //if it's nil, set default image automatically
79 |
80 | //--- failed
81 | var failedBackgroundColor:UIColor = UIColor.blackColor()
82 | var failedImage:UIImage? = nil //if it's nil, set default image automatically
83 |
84 | //PKAlert custom
85 | var alertWidth:CGFloat = 260
86 | var alertMargin:CGFloat = 8
87 | var alertTitleFontColor:UIColor = UIColor.darkGrayColor()
88 | var alertTitleFontStyle:UIFont = UIFont.boldSystemFontOfSize(17)
89 | var alertMessageFontColor:UIColor = UIColor.grayColor()
90 | var alertMessageFontStyle:UIFont = UIFont.systemFontOfSize(13)
91 | var alertButtonFontColor:UIColor = UIColor.grayColor()
92 | var alertBackgroundColor:UIColor = UIColor.whiteColor()
93 | var alertCornerRadius:CGFloat = 8
94 |
95 | //PKActionSheet custom
96 | var actionSheetMargin:CGFloat = 8
97 | var actionSheetTitleFontColor:UIColor = UIColor.darkGrayColor()
98 | var actionSheetTitleFontStyle:UIFont = UIFont.boldSystemFontOfSize(17)
99 | var actionSheetButtonFontColor:UIColor = UIColor.grayColor()
100 | var actionSheetBackgroundColor:UIColor = UIColor.whiteColor()
101 | var actionSheetCornerRadius:CGFloat = 8
102 |
103 | // MARK: - Lifecycle
104 | required init?(coder aDecoder: NSCoder) {
105 | super.init(coder: aDecoder)
106 | }
107 |
108 | required override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
109 | super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
110 | NSNotificationCenter.defaultCenter().addObserver(self, selector: "rotated", name: UIDeviceOrientationDidChangeNotification, object: nil)
111 | }
112 |
113 | override func viewDidLoad() {
114 | super.viewDidLoad()
115 | }
116 |
117 | override func didReceiveMemoryWarning() {
118 | super.didReceiveMemoryWarning()
119 | }
120 |
121 | // MARK: - Call methods
122 | func alert(title t:String?, message m:String?, items i:Array?, cancelButtonTitle c:String?, tintColor tint:UIColor?) {
123 | let alertVC:PKAlert = PKAlert(title:t, message:m, items:i, cancelButtonTitle:c, tintColor:tint, parent: self)
124 | alertVC.view.alpha = 0
125 | _PKNotificationSingleton.vcCollection.append(alertVC)
126 | alertVC.view.center = UIApplication.sharedApplication().windows[0].center
127 | UIApplication.sharedApplication().windows[0].addSubview(alertVC.view)
128 |
129 | alertVC.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
130 | UIView.animateWithDuration(0.1,
131 | delay: 0,
132 | options: UIViewAnimationOptions.CurveLinear,
133 | animations: { () -> Void in
134 | alertVC.view.alpha = 1
135 | alertVC.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1, 1);
136 | },
137 | completion: { (finished:Bool) -> Void in
138 |
139 | })
140 | }
141 |
142 | func actionSheet(title t:String?, items i:Array?, cancelButtonTitle c:String?, tintColor tint:UIColor?) {
143 | let actionSheetVC:PKActionSheet = PKActionSheet(title:t, items:i, cancelButtonTitle:c, tintColor:tint, parent: self)
144 | _PKNotificationSingleton.vcCollection.append(actionSheetVC)
145 | actionSheetVC.view.center = UIApplication.sharedApplication().windows[0].center
146 | UIApplication.sharedApplication().windows[0].addSubview(actionSheetVC.view)
147 |
148 | let w:CGFloat = actionSheetVC.rectBounds.size.width
149 | let h:CGFloat = actionSheetVC.rectBounds.size.height
150 | var actual_h:CGFloat = 0
151 | if(UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation))
152 | {
153 | actual_h = (w < h) ? w : h
154 | }
155 |
156 | if(UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation))
157 | {
158 | actual_h = (h < w) ? w : h
159 | }
160 |
161 | actionSheetVC.actionSheetView.frame = CGRectMake(
162 | actionSheetVC.actionSheetView.frame.origin.x,
163 | actual_h,
164 | actionSheetVC.actionSheetView.frame.width,
165 | actionSheetVC.actionSheetView.frame.height)
166 |
167 | UIView.animateWithDuration(0.2,
168 | delay: 0,
169 | options: UIViewAnimationOptions.CurveLinear,
170 | animations: { () -> Void in
171 | actionSheetVC.actionSheetView.frame = CGRectMake(
172 | self.actionSheetMargin,
173 | actual_h - actionSheetVC.actionSheetView.frame.height,
174 | actionSheetVC.actionSheetView.frame.width,
175 | actionSheetVC.actionSheetView.frame.height)
176 | },
177 | completion: { (finished:Bool) -> Void in
178 | })
179 | }
180 |
181 | func toast(message:String!) {
182 | let toastVC:PKToast = PKToast(message: message, parent: self)
183 | _PKNotificationSingleton.vcCollection.append(toastVC)
184 |
185 | toastVC.view.alpha = 0
186 | UIApplication.sharedApplication().windows[0].addSubview(toastVC.view)
187 |
188 | UIView.animateWithDuration(0.3,
189 | delay: 0,
190 | options: UIViewAnimationOptions.CurveLinear,
191 | animations: { () -> Void in
192 | toastVC.view.alpha = 1
193 | },
194 | completion: { (finished:Bool) -> Void in
195 | UIView.animateWithDuration(0.3,
196 | delay: 2,
197 | options: UIViewAnimationOptions.CurveLinear,
198 | animations: { () -> Void in
199 | toastVC.view.alpha = 0
200 | },
201 | completion: { (finished:Bool) -> Void in
202 | self.view.removeFromSuperview()
203 | self.removeVCCollectionByObject(toastVC)
204 | })
205 | })
206 | }
207 |
208 | func loading(flag:Bool) {
209 |
210 | if(flag && !_PKNotificationSingleton.isLoading){
211 | let progressVC:PKProgress = PKProgress(PKProgressType.Loading, nil, self)
212 | _PKNotificationSingleton.vcCollection.append(progressVC)
213 | UIApplication.sharedApplication().windows[0].addSubview(progressVC.view)
214 | _PKNotificationSingleton.isLoading = true
215 | } else if(!flag && _PKNotificationSingleton.isLoading) {
216 | let cnt:Int = 0
217 | for anyObject in _PKNotificationSingleton.vcCollection {
218 | if (anyObject.isKindOfClass(PKProgress)) {
219 | if (anyObject as! PKProgress).type == PKProgressType.Loading {
220 | (anyObject as! PKProgress).view.removeFromSuperview()
221 | _PKNotificationSingleton.vcCollection.removeAtIndex(cnt)
222 | _PKNotificationSingleton.isLoading = false
223 | }
224 | }
225 | }
226 | }
227 |
228 | }
229 |
230 | func success(message:String?) {
231 | let progressVC:PKProgress = PKProgress(PKProgressType.Success, message, self)
232 | _PKNotificationSingleton.vcCollection.append(progressVC)
233 | progressVC.view.alpha = 0
234 | UIApplication.sharedApplication().windows[0].addSubview(progressVC.view)
235 |
236 | progressVC.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
237 | UIView.animateWithDuration(0.1,
238 | delay: 0,
239 | options: UIViewAnimationOptions.CurveLinear,
240 | animations: { () -> Void in
241 | progressVC.view.alpha = 1
242 | progressVC.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1, 1);
243 | },
244 | completion: { (finished:Bool) -> Void in
245 | UIView.animateWithDuration(0.1,
246 | delay: 2,
247 | options: UIViewAnimationOptions.CurveLinear,
248 | animations: { () -> Void in
249 | progressVC.view.alpha = 0
250 | },
251 | completion: { (finished:Bool) -> Void in
252 | progressVC.view.removeFromSuperview()
253 | self.removeVCCollectionByObject(progressVC)
254 | })
255 | })
256 |
257 | }
258 |
259 | func failed(message:String?) {
260 | let progressVC:PKProgress = PKProgress(PKProgressType.Failed, message, self)
261 | _PKNotificationSingleton.vcCollection.append(progressVC)
262 | progressVC.view.alpha = 0
263 | UIApplication.sharedApplication().windows[0].addSubview(progressVC.view)
264 |
265 | progressVC.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
266 | UIView.animateWithDuration(0.1,
267 | delay: 0,
268 | options: UIViewAnimationOptions.CurveLinear,
269 | animations: { () -> Void in
270 | progressVC.view.alpha = 1
271 | progressVC.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1, 1);
272 | },
273 | completion: { (finished:Bool) -> Void in
274 | UIView.animateWithDuration(0.1,
275 | delay: 2,
276 | options: UIViewAnimationOptions.CurveLinear,
277 | animations: { () -> Void in
278 | progressVC.view.alpha = 0
279 | },
280 | completion: { (finished:Bool) -> Void in
281 | progressVC.view.removeFromSuperview()
282 | self.removeVCCollectionByObject(progressVC)
283 | })
284 | })
285 | }
286 |
287 | // MARK: - Common methods
288 | private func generateBackground(color color:UIColor, uiEnabled:Bool) -> UIView {
289 | let backgroundView = UIView()
290 | let mainScreenFrame:CGRect = UIScreen.mainScreen().bounds
291 | let length:CGFloat = (mainScreenFrame.width < mainScreenFrame.height) ? mainScreenFrame.height : mainScreenFrame.width
292 | backgroundView.frame = CGRectMake(0, 0, length, length)
293 | backgroundView.backgroundColor = color
294 | backgroundView.userInteractionEnabled = uiEnabled
295 | return backgroundView
296 | }
297 |
298 | func rotated()
299 | {
300 | for anyObject in _PKNotificationSingleton.vcCollection {
301 | if (anyObject.isKindOfClass(PKAlert)) {
302 | (anyObject as! PKAlert).rotate()
303 | }
304 |
305 | if (anyObject.isKindOfClass(PKActionSheet)) {
306 | (anyObject as! PKActionSheet).rotate()
307 | }
308 |
309 | if (anyObject.isKindOfClass(PKToast)) {
310 | (anyObject as! PKToast).rotate()
311 | }
312 |
313 | if (anyObject.isKindOfClass(PKProgress)) {
314 | (anyObject as! PKProgress).rotate()
315 | }
316 | }
317 |
318 | }
319 |
320 | private func removeVCCollectionByObject(target:UIViewController) -> Void {
321 | let cnt:Int = 0;
322 | for vc:UIViewController in _PKNotificationSingleton.vcCollection {
323 | if (vc == target){
324 | _PKNotificationSingleton.vcCollection.removeAtIndex(cnt)
325 | break;
326 | }
327 | }
328 | }
329 |
330 | // MARK: - @CLASS PKAlert
331 | class PKAlert: UIViewController {
332 | var parent:PKNotificationClass!
333 | let alertView:UIView = UIView(frame: CGRectMake(0, 0, 100, 100))
334 | var titleLabel:UILabel? = nil
335 | var items:Array = []
336 | var messageLabel:UILabel? = nil
337 | var cancelButton:PKButton! = PKButton()
338 |
339 | // MARK: - Lifecycle
340 | convenience init(title t:String?, message m:String?, items i:Array?, cancelButtonTitle c:String?, tintColor tint:UIColor?, parent p:PKNotificationClass) {
341 | /* initialize alert parts, resize them and set colors */
342 | self.init()
343 | parent = p
344 | let tintColor:UIColor! = (tint == nil) ? parent.alertButtonFontColor : tint
345 |
346 | titleLabel = (t == nil) ? nil : UILabel()
347 | titleLabel?.text = t
348 |
349 | messageLabel = (m == nil) ? nil : UILabel()
350 | messageLabel?.text = m
351 |
352 |
353 | if let tmpItems = i {
354 | for b:AnyObject in tmpItems {
355 | if (b is PKButton){
356 | //TODO: Precise color choise
357 | let titleColor:UIColor? = ((b as! PKButton).titleLabel?.textColor == UIColor.whiteColor()) ? nil : (b as! PKButton).titleLabel?.textColor
358 | (b as! PKButton).setTitleColor((titleColor == nil) ? tintColor : titleColor, forState: UIControlState.Normal)
359 | (b as! PKButton).backgroundColor = ((b as! PKButton).backgroundColor == nil) ? self.parent.alertBackgroundColor : b.backgroundColor
360 | (b as! PKButton).addTarget(self, action:"buttonDown:", forControlEvents: UIControlEvents.TouchUpInside)
361 | items.append((b as! PKButton))
362 | } else if (b.isKindOfClass(UITextField) || b is UIButton){
363 | let theLast:AnyObject? = items.last
364 | if (theLast != nil) {
365 | if(!theLast!.isKindOfClass(UITextField) && !(theLast! is UIButton)){
366 | continue
367 | }
368 | }
369 | if(b.isKindOfClass(UITextField)){
370 | items.append(b as! UITextField)
371 | } else if (b is UIButton){
372 | items.append(b as! UIButton)
373 | }
374 | }
375 | }
376 | }
377 |
378 | let cancelButtonTitle:String! = (c == nil) ? "Dissmiss" : c
379 | cancelButton = PKButton(title: cancelButtonTitle!, action: {(items) -> Bool in return true}, fontColor: tintColor, backgroundColor: parent.alertBackgroundColor)
380 | cancelButton.addTarget(self, action:"buttonDown:", forControlEvents: UIControlEvents.TouchUpInside)
381 |
382 | /* put parts on an alertview and add it as subview on self.view */
383 | resizeParts()
384 | let alertBackgroundView = parent.generateBackground(color: UIColor.blackColor(), uiEnabled: true)
385 | alertBackgroundView.alpha = 0.3
386 | if(titleLabel != nil){ alertView.addSubview(titleLabel!)}
387 | if(messageLabel != nil){ alertView.addSubview(messageLabel!)}
388 | for b:AnyObject in items {
389 | alertView.addSubview((b as! UIView))
390 | }
391 | alertView.addSubview(cancelButton)
392 | self.view.addSubview(alertBackgroundView)
393 | self.view.addSubview(alertView)
394 | }
395 |
396 | required init?(coder aDecoder: NSCoder) {
397 | super.init(coder: aDecoder)
398 | }
399 |
400 | required override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
401 | super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
402 | //NSLog("########### \(NSStringFromClass(self.dynamicType)): \(self) is initialized. ###########")
403 | }
404 |
405 | override func viewDidLoad() {
406 | super.viewDidLoad()
407 | let tapRecognizer = UITapGestureRecognizer(target: self, action: "handleSingleTap:")
408 | tapRecognizer.numberOfTapsRequired = 1
409 | self.view.addGestureRecognizer(tapRecognizer)
410 | }
411 |
412 | override func didReceiveMemoryWarning() {
413 | super.didReceiveMemoryWarning()
414 | }
415 |
416 | deinit {
417 | //NSLog("########### \(NSStringFromClass(self.dynamicType)): \(self) is deinitialized. ###########")
418 | }
419 |
420 | // MARK: - UI
421 | func resizeParts() -> Void {
422 | /* set layout and adjust button shape */
423 | let margin:CGFloat = parent.alertMargin
424 | let messageLabelWidth:CGFloat = parent.alertWidth - margin*2
425 | let lineColor:UIColor = UIColor(red: 0.9, green: 0.9, blue: 0.9, alpha: 1.0)
426 | let titlePosY:CGFloat = margin
427 | titleLabel?.frame = CGRectMake(margin, titlePosY, messageLabelWidth, 40)
428 | titleLabel?.textColor = parent.alertTitleFontColor
429 | titleLabel?.font = parent.alertTitleFontStyle
430 | titleLabel?.textAlignment = NSTextAlignment.Center
431 |
432 | let messagePosY:CGFloat = (titleLabel == nil) ? titlePosY + margin*2 : titlePosY + titleLabel!.frame.height + margin
433 | messageLabel?.textColor = parent.alertMessageFontColor
434 | messageLabel?.font = parent.alertMessageFontStyle
435 | messageLabel?.textAlignment = NSTextAlignment.Center
436 | messageLabel?.numberOfLines = 0
437 | messageLabel?.frame = CGRectMake(margin, messagePosY, messageLabelWidth, 44)
438 | messageLabel?.sizeToFit()
439 | messageLabel?.frame = CGRectMake((parent.alertWidth - messageLabel!.frame.width)/2, messagePosY, messageLabel!.frame.width, messageLabel!.frame.height)
440 |
441 | var buttonPosY:CGFloat = (messageLabel == nil) ? messagePosY + margin*2 : messagePosY + messageLabel!.frame.height + margin*2
442 |
443 | for b:AnyObject in items {
444 | if (b.isKindOfClass(UITextField)){
445 | (b as! UITextField).frame = CGRectMake(parent.alertMargin, buttonPosY, self.parent.alertWidth - 2 * parent.alertMargin, 44)
446 | (b as! UITextField).layer.sublayerTransform = CATransform3DMakeTranslation(5, 0, 0);
447 | (b as! UITextField).font = parent.alertMessageFontStyle
448 | buttonPosY += b.frame.height + margin
449 | } else if (b.isKindOfClass(PKButton)){
450 | (b as! PKButton).frame = CGRectMake(0, buttonPosY, self.parent.alertWidth, 44)
451 | let rectButton:CGRect = b.bounds
452 | let rectButtonMask:CGRect = CGRectMake(1, 0, rectButton.width-2, rectButton.height-1)
453 | let maskPath:UIBezierPath = UIBezierPath(rect:rectButtonMask)
454 | let maskLayer:CAShapeLayer = CAShapeLayer()
455 | maskLayer.frame = b.bounds
456 | maskLayer.path = maskPath.CGPath
457 | b.layer.mask = maskLayer
458 | b.layer.borderWidth = 1.0
459 | b.layer.borderColor = lineColor.CGColor
460 | buttonPosY += b.frame.height
461 | } else if (b is UIButton){
462 | (b as! UIButton).frame = CGRectMake(0, buttonPosY, self.parent.alertWidth - 2 * parent.alertMargin, 44)
463 | buttonPosY += b.frame.height + margin
464 | }
465 | }
466 |
467 | cancelButton.frame = CGRectMake(0, buttonPosY, parent.alertWidth, 44)
468 | let rectCancelButton:CGRect = cancelButton.bounds
469 | let rectCancelButtonMask:CGRect = CGRectMake(1, 0, rectCancelButton.width-2, rectCancelButton.height-1)
470 |
471 | let maskPath:UIBezierPath = UIBezierPath(roundedRect: rectCancelButtonMask, byRoundingCorners: [UIRectCorner.BottomLeft, UIRectCorner.BottomRight], cornerRadii: CGSizeMake(parent.alertCornerRadius, parent.alertCornerRadius))
472 | let maskLayer:CAShapeLayer = CAShapeLayer()
473 | maskLayer.frame = cancelButton.bounds
474 | maskLayer.path = maskPath.CGPath
475 | cancelButton.layer.mask = maskLayer
476 | cancelButton.layer.borderWidth = 1.0
477 | cancelButton.layer.borderColor = lineColor.CGColor
478 |
479 | let kAlertHeight:CGFloat = cancelButton.frame.origin.y + cancelButton.frame.height
480 | alertView.frame.size = CGSizeMake(parent.alertWidth, kAlertHeight)
481 | alertView.backgroundColor = parent.alertBackgroundColor
482 | alertView.layer.cornerRadius = parent.alertCornerRadius
483 | alertView.center = UIApplication.sharedApplication().windows[0].center
484 |
485 | }
486 |
487 | func handleSingleTap(recognizer: UITapGestureRecognizer) {
488 | self.view.endEditing(true)
489 | }
490 |
491 | func rotate() -> Void {
492 | let point:CGPoint = UIApplication.sharedApplication().windows[0].center
493 | if(UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation))
494 | {
495 | alertView.center = point
496 | }
497 |
498 | if(UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation))
499 | {
500 | alertView.center = point
501 | }
502 | }
503 |
504 | // MARK: - button action
505 | func buttonDown(sender: PKButton!) -> Void {
506 | if (sender.actionBlock(messageLabel: messageLabel, items: items)) {
507 | //Dissmiss alert
508 | UIView.animateWithDuration(0.1,
509 | delay: 0,
510 | options: UIViewAnimationOptions.CurveLinear,
511 | animations: { () -> Void in
512 | self.view.alpha = 0
513 | },
514 | completion: { (finished:Bool) -> Void in
515 | self.view.removeFromSuperview()
516 | let cnt:Int = 0;
517 | for vc:UIViewController in _PKNotificationSingleton.vcCollection {
518 | if (vc == self){
519 | _PKNotificationSingleton.vcCollection.removeAtIndex(cnt)
520 | break;
521 | }
522 |
523 | }
524 | })
525 | }
526 | resizeParts()
527 | }
528 | }
529 |
530 |
531 | // MARK: - @CLASS PKActionSheet
532 | class PKActionSheet: UIViewController {
533 | var parent:PKNotificationClass!
534 | let rectBounds:CGRect = UIScreen.mainScreen().bounds
535 | let actionSheetView:UIView = UIView(frame: CGRectMake(0, 0, 100, 100))
536 | var titleLabel:UILabel? = nil
537 | var items:Array = []
538 | var cancelButton:PKButton! = PKButton()
539 |
540 | // MARK: - Lifecycle
541 | convenience init(title t:String?, items i:Array?, cancelButtonTitle c:String?, tintColor tint:UIColor?, parent p:PKNotificationClass) {
542 | /* initialize alert parts, resize them and set colors */
543 | self.init()
544 | parent = p
545 | let tintColor:UIColor! = (tint == nil) ? parent.actionSheetButtonFontColor : tint
546 |
547 | titleLabel = (t == nil) ? nil : UILabel()
548 | titleLabel?.text = t
549 |
550 | if let tmpItems = i {
551 | for b:PKButton in tmpItems {
552 | //TODO: Precise color choise
553 | let titleColor:UIColor? = (b.titleLabel?.textColor == UIColor.whiteColor()) ? nil : b.titleLabel?.textColor
554 | b.setTitleColor((titleColor == nil) ? tintColor : titleColor, forState: UIControlState.Normal)
555 | b.backgroundColor = (b.backgroundColor == nil) ? self.parent.actionSheetBackgroundColor : b.backgroundColor
556 | b.addTarget(self, action:"buttonDown:", forControlEvents: UIControlEvents.TouchUpInside)
557 | items.append(b)
558 | }
559 | }
560 |
561 | let cancelButtonTitle:String! = (c == nil) ? "Dissmiss" : c
562 | cancelButton = PKButton(title: cancelButtonTitle!, action: {(items) -> Bool in return true}, fontColor: tintColor, backgroundColor: parent.actionSheetBackgroundColor)
563 | cancelButton.addTarget(self, action:"buttonDown:", forControlEvents: UIControlEvents.TouchUpInside)
564 |
565 | /* put parts on an alertview and add it as subview on self.view */
566 | resizeParts()
567 | let actionSheetBackgroundView = parent.generateBackground(color: UIColor.blackColor(), uiEnabled: true)
568 | actionSheetBackgroundView.alpha = 0.3
569 | if(titleLabel != nil){ actionSheetView.addSubview(titleLabel!)}
570 | for b:AnyObject in items {
571 | actionSheetView.addSubview((b as! UIView))
572 | }
573 | actionSheetView.addSubview(cancelButton)
574 | self.view.addSubview(actionSheetBackgroundView)
575 | self.view.addSubview(actionSheetView)
576 | }
577 |
578 | required init?(coder aDecoder: NSCoder) {
579 | super.init(coder: aDecoder)
580 | }
581 |
582 | required override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
583 | super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
584 | //NSLog("########### \(NSStringFromClass(self.dynamicType)): \(self) is initialized. ###########")
585 | }
586 |
587 | override func viewDidLoad() {
588 | super.viewDidLoad()
589 | let tapRecognizer = UITapGestureRecognizer(target: self, action: "handleSingleTap:")
590 | tapRecognizer.numberOfTapsRequired = 1
591 | self.view.addGestureRecognizer(tapRecognizer)
592 | }
593 |
594 | override func didReceiveMemoryWarning() {
595 | super.didReceiveMemoryWarning()
596 | }
597 |
598 | deinit {
599 | //NSLog("########### \(NSStringFromClass(self.dynamicType)): \(self) is deinitialized. ###########")
600 | }
601 |
602 | // MARK: - UI
603 | func resizeParts() -> Void {
604 | /* set layout and adjust button shape */
605 | let margin:CGFloat = parent.actionSheetMargin
606 | let lineColor:UIColor = UIColor(red: 0.9, green: 0.9, blue: 0.9, alpha: 1.0)
607 | let titlePosY:CGFloat = margin
608 | let w:CGFloat = UIScreen.mainScreen().bounds.width
609 | //let w:CGFloat = (UIScreen.mainScreen().bounds.width < UIScreen.mainScreen().bounds.height) ? UIScreen.mainScreen().bounds.width : UIScreen.mainScreen().bounds.height
610 | let actionSheetWidth:CGFloat = w - margin*2
611 | titleLabel?.frame = CGRectMake(0, titlePosY, actionSheetWidth, 40)
612 | titleLabel?.textColor = parent.actionSheetTitleFontColor
613 | titleLabel?.font = parent.actionSheetTitleFontStyle
614 | titleLabel?.textAlignment = NSTextAlignment.Center
615 |
616 | var buttonPosY:CGFloat = (titleLabel == nil) ? 0: titlePosY + titleLabel!.frame.height + margin
617 |
618 | for b:PKButton in items {
619 | b.frame = CGRectMake(0, buttonPosY, actionSheetWidth, 44)
620 | let rectButton:CGRect = b.bounds
621 |
622 | if(b.isEqual(items.first) && titleLabel == nil){
623 | let rectButtonMaskr:CGRect = CGRectMake(1, 1, rectButton.width-2, rectButton.height-2)
624 | let maskPathr:UIBezierPath = UIBezierPath(roundedRect: rectButtonMaskr, byRoundingCorners: [UIRectCorner.TopLeft, UIRectCorner.TopRight], cornerRadii: CGSizeMake(parent.actionSheetCornerRadius, parent.actionSheetCornerRadius))
625 | let maskLayerr:CAShapeLayer = CAShapeLayer()
626 | maskLayerr.frame = b.bounds
627 | maskLayerr.path = maskPathr.CGPath
628 | b.layer.mask = maskLayerr
629 | b.layer.borderWidth = 1.0
630 | b.layer.borderColor = lineColor.CGColor
631 |
632 | } else {
633 | let rectButtonMask:CGRect = CGRectMake(1, 0, rectButton.width-2, rectButton.height-1)
634 | let maskPath:UIBezierPath = UIBezierPath(rect:rectButtonMask)
635 | let maskLayer:CAShapeLayer = CAShapeLayer()
636 | maskLayer.frame = b.bounds
637 | maskLayer.path = maskPath.CGPath
638 | b.layer.mask = maskLayer
639 | b.layer.borderWidth = 1.0
640 | b.layer.borderColor = lineColor.CGColor
641 | }
642 | buttonPosY += b.frame.height
643 | }
644 |
645 | cancelButton.frame = CGRectMake(0, buttonPosY, actionSheetWidth, 44)
646 | let rectCancelButton:CGRect = cancelButton.bounds
647 | let rectCancelButtonMask:CGRect = CGRectMake(1, 0, rectCancelButton.width-2, rectCancelButton.height-1)
648 |
649 | let maskPath:UIBezierPath = UIBezierPath(roundedRect: rectCancelButtonMask, byRoundingCorners: [UIRectCorner.BottomLeft, UIRectCorner.BottomRight], cornerRadii: CGSizeMake(parent.actionSheetCornerRadius, parent.actionSheetCornerRadius))
650 | let maskLayer:CAShapeLayer = CAShapeLayer()
651 | maskLayer.frame = cancelButton.bounds
652 | maskLayer.path = maskPath.CGPath
653 | cancelButton.layer.mask = maskLayer
654 | cancelButton.layer.borderWidth = 1.0
655 | cancelButton.layer.borderColor = lineColor.CGColor
656 |
657 | let kActionSheetHeight:CGFloat = cancelButton.frame.origin.y + cancelButton.frame.height
658 | actionSheetView.frame.size = CGSizeMake(actionSheetWidth, kActionSheetHeight)
659 | actionSheetView.backgroundColor = parent.actionSheetBackgroundColor
660 | actionSheetView.layer.cornerRadius = parent.actionSheetCornerRadius
661 | //actionSheetView.center = UIApplication.sharedApplication().windows[0].center
662 |
663 | }
664 |
665 | func handleSingleTap(recognizer: UITapGestureRecognizer) {
666 | self.view.endEditing(true)
667 | }
668 |
669 | func rotate() -> Void {
670 | let w:CGFloat = rectBounds.size.width
671 | let h:CGFloat = rectBounds.size.height
672 | var actual_h:CGFloat = 0
673 | if(UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation))
674 | {
675 | actual_h = (w < h) ? w : h
676 | }
677 |
678 | if(UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation))
679 | {
680 | actual_h = (h < w) ? w : h
681 | }
682 | resizeParts()
683 | actionSheetView.frame = CGRectMake(
684 | parent.actionSheetMargin,
685 | actual_h - actionSheetView.frame.height,
686 | actionSheetView.frame.width,
687 | actionSheetView.frame.height)
688 |
689 | }
690 |
691 | // MARK: - button action
692 | func buttonDown(sender: PKButton!) -> Void {
693 | if (sender.actionBlock(messageLabel: nil, items: items)) {
694 | //Dissmiss actionSheet
695 | let w:CGFloat = rectBounds.size.width
696 | let h:CGFloat = rectBounds.size.height
697 | var actual_h:CGFloat = 0
698 | if(UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation))
699 | {
700 | actual_h = (w < h) ? w : h
701 | }
702 |
703 | if(UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation))
704 | {
705 | actual_h = (h < w) ? w : h
706 | }
707 |
708 | UIView.animateWithDuration(0.2,
709 | delay: 0,
710 | options: UIViewAnimationOptions.CurveLinear,
711 | animations: { () -> Void in
712 | self.actionSheetView.frame = CGRectMake(
713 | self.actionSheetView.frame.origin.x,
714 | actual_h,
715 | self.actionSheetView.frame.width,
716 | self.actionSheetView.frame.height)
717 | self.view.alpha = 0
718 | },
719 | completion: { (finished:Bool) -> Void in
720 | self.view.removeFromSuperview()
721 | let cnt:Int = 0;
722 | for vc:UIViewController in _PKNotificationSingleton.vcCollection {
723 | if (vc == self){
724 | _PKNotificationSingleton.vcCollection.removeAtIndex(cnt)
725 | break;
726 | }
727 |
728 | }
729 | })
730 | }
731 | }
732 | }
733 |
734 |
735 | // MARK: - @CLASS PKToast
736 | class PKToast: UIViewController {
737 | var parent:PKNotificationClass!
738 | let rectBounds:CGRect = UIScreen.mainScreen().bounds
739 | let toastView:UIView = UIView()
740 | let messageLabel:UILabel = UILabel()
741 |
742 | //toast Rect
743 | var posX:CGFloat = 0
744 | var posY:CGFloat = 0
745 | var width:CGFloat = 0
746 | var height:CGFloat = 0
747 |
748 | // MARK: - Lifecycle
749 | convenience init(message m:String, parent p:PKNotificationClass) {
750 | self.init()
751 | parent = p
752 | generate(message: m)
753 | }
754 |
755 | required init?(coder aDecoder: NSCoder) {
756 | super.init(coder: aDecoder)
757 | }
758 |
759 | required override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
760 | super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
761 | //NSLog("########### \(NSStringFromClass(self.dynamicType)) is initialized. ###########")
762 | }
763 |
764 | override func viewDidLoad() {
765 | super.viewDidLoad()
766 | }
767 |
768 | override func didReceiveMemoryWarning() {
769 | super.didReceiveMemoryWarning()
770 | }
771 |
772 | deinit {
773 | //NSLog("########### \(NSStringFromClass(self.dynamicType)) is deinitialized. ###########")
774 | }
775 |
776 | // MARK: - generate
777 | func generate(message m:String) {
778 | posX = parent.toastMargin
779 | posY = rectBounds.size.height - parent.toastMargin - parent.toastHeight
780 | width = rectBounds.size.width - parent.toastMargin * 2
781 | height = parent.toastHeight
782 | let rectToast:CGRect = CGRectMake(posX, posY, width, height)
783 | toastView.frame = rectToast
784 | messageLabel.frame = CGRectMake(0, 0, rectToast.width, rectToast.height)
785 |
786 | toastView.backgroundColor = parent.toastBackgroundColor
787 | toastView.alpha = parent.toastAlpha
788 | toastView.layer.cornerRadius = parent.toastRadious
789 | messageLabel.font = parent.toastFontStyle
790 | messageLabel.textColor = parent.toastFontColor
791 | messageLabel.textAlignment = NSTextAlignment.Center
792 | messageLabel.text = m
793 | toastView.addSubview(messageLabel)
794 | self.view.userInteractionEnabled = false
795 | self.view.addSubview(toastView)
796 | }
797 |
798 | func rotate() -> Void {
799 | let w:CGFloat = rectBounds.size.width
800 | let h:CGFloat = rectBounds.size.height
801 | if(UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation))
802 | {
803 | posY = (h < w) ? h - parent.toastMargin - parent.toastHeight : w - parent.toastMargin - parent.toastHeight
804 | width = (h < w) ? w - parent.toastMargin * 2 : h - parent.toastMargin * 2
805 | }
806 |
807 | if(UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation))
808 | {
809 | posY = (w < h) ? h - parent.toastMargin - parent.toastHeight : w - parent.toastMargin - parent.toastHeight
810 | width = (w < h) ? w - parent.toastMargin * 2 : h - parent.toastMargin * 2
811 | }
812 | toastView.frame = CGRectMake(posX, posY, width, height)
813 | messageLabel.frame = CGRectMake(0, 0, toastView.frame.width, toastView.frame.height)
814 | }
815 | }
816 |
817 | // MARK: - @CLASS PKProgress
818 | class PKProgress: UIViewController {
819 |
820 | var parent:PKNotificationClass!
821 | let kMargin:CGFloat = 30
822 | let rectBounds:CGRect = UIScreen.mainScreen().bounds
823 | let progressView:UIView = UIView()
824 | var type:PKProgressType = .Loading
825 |
826 | // MARK: - Lifecycle
827 | convenience init(_ t:PKProgressType, _ m:String?, _ p:PKNotificationClass) {
828 | self.init()
829 | parent = p
830 | type = t
831 | switch(t){
832 | case .Loading:
833 | generateLoading()
834 | break
835 | case .Success:
836 | generateSuccess(m)
837 | break
838 | case .Failed:
839 | generateFailed(m)
840 | break
841 | }
842 | }
843 |
844 | required init?(coder aDecoder: NSCoder) {
845 | super.init(coder: aDecoder)
846 | }
847 |
848 | required override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
849 | super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
850 | //NSLog("########### \(NSStringFromClass(self.dynamicType)) is initialized. ###########")
851 | }
852 |
853 | override func viewDidLoad() {
854 | super.viewDidLoad()
855 | }
856 |
857 | override func didReceiveMemoryWarning() {
858 | super.didReceiveMemoryWarning()
859 | }
860 |
861 | deinit {
862 | //NSLog("########### \(NSStringFromClass(self.dynamicType)) is deinitialized. ###########")
863 | }
864 |
865 | // MARK: - generate
866 | func generateLoading(){
867 | progressView.frame = CGRectMake(0, 0, parent.progressWidth, parent.progressHeight)
868 | progressView.center = self.view.center
869 | progressView.backgroundColor = parent.loadingBackgroundColor
870 | progressView.alpha = parent.progressAlpha
871 | progressView.layer.cornerRadius = parent.progressRadious
872 |
873 | let ai:UIActivityIndicatorView = UIActivityIndicatorView() as UIActivityIndicatorView
874 | ai.frame = CGRectMake(
875 | (progressView.frame.width - ai.frame.width)/2,
876 | (progressView.frame.height - ai.frame.height)/2,
877 | ai.frame.width,
878 | ai.frame.height)
879 | ai.activityIndicatorViewStyle = parent.loadingActiveIndicatorStyle
880 | ai.hidesWhenStopped = true
881 | ai.startAnimating()
882 | progressView.addSubview(ai)
883 | self.view.addSubview(progressView)
884 | self.view.userInteractionEnabled = false
885 | }
886 |
887 | func generateSuccess(m:String?){
888 | progressView.frame = CGRectMake(0, 0, parent.progressWidth, parent.progressHeight)
889 | progressView.center = self.view.center
890 | progressView.backgroundColor = parent.successBackgroundColor
891 | progressView.alpha = parent.progressAlpha
892 | progressView.layer.cornerRadius = parent.progressRadious
893 |
894 | let imageSize:CGSize = CGSizeMake(parent.progressWidth - kMargin*2, parent.progressHeight - kMargin*2)
895 | let imageView:UIImageView = UIImageView(frame: CGRectMake(0, 0, imageSize.width, imageSize.height))
896 | imageView.image = parent.successImage == nil ? parent.defaultSuccessImage : parent.successImage
897 | imageView.frame.origin = CGPointMake(kMargin, kMargin)
898 |
899 | if(m != nil){
900 | let messageLabel:UILabel = UILabel()
901 | messageLabel.frame = CGRectMake(0, parent.progressHeight - parent.progressLabelHeight, parent.progressWidth, parent.progressLabelHeight)
902 | messageLabel.font = parent.progressFontStyle
903 | messageLabel.textColor = parent.progressFontColor
904 | messageLabel.textAlignment = NSTextAlignment.Center
905 | messageLabel.text = m
906 | imageView.frame.origin = CGPointMake(kMargin, kMargin - parent.progressLabelHeight/4)
907 | progressView.addSubview(messageLabel)
908 | }
909 | progressView.addSubview(imageView)
910 | self.view.userInteractionEnabled = false
911 | self.view.addSubview(progressView)
912 | }
913 |
914 | func generateFailed(m:String?){
915 | progressView.frame = CGRectMake(0, 0, parent.progressWidth, parent.progressHeight)
916 | progressView.center = self.view.center
917 | progressView.backgroundColor = parent.failedBackgroundColor
918 | progressView.alpha = parent.progressAlpha
919 | progressView.layer.cornerRadius = parent.progressRadious
920 |
921 | let imageSize:CGSize = CGSizeMake(parent.progressWidth - kMargin*2, parent.progressHeight - kMargin*2)
922 | let imageView:UIImageView = UIImageView(frame: CGRectMake(0, 0, imageSize.width, imageSize.height))
923 | imageView.image = parent.failedImage == nil ? parent.defaultFailedImage : parent.failedImage
924 | imageView.frame.origin = CGPointMake(kMargin, kMargin)
925 |
926 | if(m != nil){
927 | let messageLabel:UILabel = UILabel()
928 | messageLabel.frame = CGRectMake(0, parent.progressHeight - parent.progressLabelHeight, parent.progressWidth, parent.progressLabelHeight)
929 | messageLabel.font = parent.progressFontStyle
930 | messageLabel.textColor = parent.progressFontColor
931 | messageLabel.textAlignment = NSTextAlignment.Center
932 | messageLabel.text = m
933 | imageView.frame.origin = CGPointMake(kMargin, kMargin - parent.progressLabelHeight/4)
934 | progressView.addSubview(messageLabel)
935 | }
936 | progressView.addSubview(imageView)
937 | self.view.userInteractionEnabled = false
938 | self.view.addSubview(progressView)
939 | }
940 |
941 | func rotate() -> Void {
942 | let point:CGPoint = UIApplication.sharedApplication().windows[0].center
943 | if(UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation))
944 | {
945 | progressView.center = point
946 | }
947 |
948 | if(UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation))
949 | {
950 | progressView.center = point
951 | }
952 | }
953 | }
954 |
955 | // MARK: - @CLASS Images
956 | class Images {
957 | func success() -> UIImage {
958 | let base64Str:String = "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gwcEAgrQ5wC4QAAAXdJREFUeNrt2DFKA0EYhuHRM3gSIb2F2KX0JLYpLHMW72IhWIn3CAHhs1khlUYx8Yv7vJAuxc7/7DDMjiFJkiRJkiRJkiRJkiRJ2i3JVZJrk+jAWCZ5TPKc5NZEOjA+glKEAaUQA0ohxi7KXgf9ubH+HGOMcT/GuNzj79sxxpup/f3OyPS/panBgAEDBgwYMAQDhmDAEAwY+iWMRZLtnhjbJAtTszNgwIABA4YDXLPYGUnOklzA6MG4SfJwCg8+F4ynnQUsYHRg7B5+y8Ln/b8H+CcYlW/XXHdG5cL+/T0jycV0gNcvcDaXvlNY6Oxu4NOCt40Lnu0NfFp41Vs4+29TTQPwobBoEDCKBgKj6KCHUXTQwygaFIyigcEoQoFRhAKjCAVGEQqMIhQYXSiv0w9GEQqME0OBUYQCowgFxoFRXr6B8QLj8CirJJs9MDZJViZ2HJT1FyibJGuT6kCBUYQCowgFRhHKXZI7k5AkSZIkSZIkSZKO0Ds6sLt1lfeMOAAAAABJRU5ErkJggg=="
959 | let imgData:NSData = NSData(base64EncodedString: base64Str, options: NSDataBase64DecodingOptions.IgnoreUnknownCharacters)!
960 | let image:UIImage = UIImage(data: imgData)!
961 |
962 | return image
963 | }
964 |
965 | func failed() -> UIImage {
966 | let base64Str:String = "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gwcEAgdjCaXeAAAAz9JREFUeNrt3D1sTWEcx/Hv4yWhioi2BFUhFjGIKvHS7h26t43UwMruZZBUJAYGWxODQbCZxCzxEonBIBYhWvHSllQpkVA/yzMI9173ntuee87p75Pc5aTPef4vec55+gwHzMzMzMzMzMzMzMzMzMzMzBYCSc2SBiTdljQdf7fjteYC5rtYUpekEUkT8TcSry1udHAD+r+BAjWjq4p8uxoV3LCqN1yAZgzVkO9QFldGYVZKlStjTlZKSPLOAL4kzG1lCGEmb+8M4GfC4UtCCLO1DFiUYJK+OvLry+EC2Z3m2CQNOVxHgIdz2JBjaY5N8siaBlYlDPBzCGF1zh5ZE0BrwuGTIYS2+V4hNo+SNOReHfPdy2GNbqU5NklDrtUR4LUcNuRKmmO97c37tjcWdDBBcIN5a0bMdxbYm2Do3lqb4aOTohyd1HiE4sPFlIP08XtWjt/NzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMbG6ErAYmKQBNwFpgA7AZ6AC2AO3xWguwJv7dIuAX8A2YAj4Ab4HXwCtgFBiL1z4C30IIckPKF78N2AEcBHqBAylM/QC4A9wHngETjW5SaGATWoH9QD+QpY8L3ABuAg9DCJOFfj5Kapd0XNK48mE8xttepCY0S+qXNKZ8G4t5NOe1EZskXVIxXZK0KRfvEEkdwHmSfcLpT+PAc+Bl3CG9Ad4Dk3EXNQ18Bb4DPwDFfJYCy4AVwOq4C2sF1gMb405tK7AdWFdnjNeBUyGE0cw1RNIa4CxwIsHwF8Aj4DHwBHiaxgs1bix2AruAPcA+YFuCW10GzoYQprLyeOqvccm/k3Q1foOqI2OP2o4Y19UYZy36Gx18m6S7VQY7KumipJ6cvQt7YtyjVeZ5V1JbIwLtrjLA65J6C7Jj7I35VKM7zcCO/ieYT5LOFWr//u//U+dinpUcTSOY0xUCmJF0RlLTQjgIlNQU852pUJPT8xnAyQoTX5bUshBPaCW1xPzLOTkfkx4pM9mjVJ+X2W5Md6xHKUfmcqLOMpNccBtK1utCmXp1zsXNl5e48aykQZe+Yt0GY53+trzeGw+XOAE95JJXVbtDJU62h10ZMzMzMzPLkt8vA/1E0dnMwQAAAABJRU5ErkJggg=="
967 | let imgData:NSData = NSData(base64EncodedString: base64Str, options: NSDataBase64DecodingOptions.IgnoreUnknownCharacters)!
968 | let image:UIImage = UIImage(data: imgData)!
969 |
970 | return image
971 | }
972 | }
973 | }
974 |
975 | // MARK: - @CLASS PKButton
976 | class PKButton: UIButton {
977 | var actionBlock:PKButtonActionBlock = {(item) -> Bool in return true}
978 |
979 | convenience init(title t:String, action a:PKButtonActionBlock, fontColor f:UIColor?, backgroundColor b:UIColor?) {
980 | self.init()
981 | actionBlock = a
982 | self.setTitle(t, forState: UIControlState.Normal)
983 | self.setTitleColor(f, forState: UIControlState.Normal)
984 | self.backgroundColor = b
985 | self.titleLabel?.textAlignment = NSTextAlignment.Center
986 | }
987 |
988 | required init?(coder aDecoder: NSCoder) {
989 | super.init(coder: aDecoder)
990 | }
991 |
992 | override init(frame aFrame: CGRect) {
993 | super.init(frame: aFrame)
994 | }
995 |
996 | }
997 |
998 | extension String {
999 | var floatValue: Float {
1000 | return (self as NSString).floatValue
1001 | }
1002 | }
1003 |
1004 |
--------------------------------------------------------------------------------