├── Screenshots
├── image.png
├── new_1.PNG
├── new_2.PNG
├── new_3.PNG
├── single.png
├── title.png
├── activity.png
└── activity_message.PNG
├── SwiftToastDemo
├── ToastDemo
│ ├── Images.xcassets
│ │ ├── swift-logo.imageset
│ │ │ ├── swift-logo.png
│ │ │ └── Contents.json
│ │ ├── small-image.imageset
│ │ │ ├── exclamation-toast.png
│ │ │ ├── exclamation-toast@2x.png
│ │ │ ├── exclamation-toast@3x.png
│ │ │ └── Contents.json
│ │ ├── LaunchImage.launchimage
│ │ │ └── Contents.json
│ │ └── AppIcon.appiconset
│ │ │ └── Contents.json
│ ├── AppDelegate.swift
│ ├── Info.plist
│ ├── Base.lproj
│ │ └── Main.storyboard
│ ├── Launch Screen.storyboard
│ └── ViewController.swift
├── ToastDemo.xcodeproj
│ ├── xcuserdata
│ │ ├── mac.xcuserdatad
│ │ │ ├── xcdebugger
│ │ │ │ └── Breakpoints_v2.xcbkptlist
│ │ │ └── xcschemes
│ │ │ │ ├── xcschememanagement.plist
│ │ │ │ └── ToastDemo.xcscheme
│ │ ├── mark.xcuserdatad
│ │ │ ├── xcdebugger
│ │ │ │ └── Breakpoints_v2.xcbkptlist
│ │ │ └── xcschemes
│ │ │ │ ├── xcschememanagement.plist
│ │ │ │ └── ToastDemo.xcscheme
│ │ ├── p2p.xcuserdatad
│ │ │ ├── xcdebugger
│ │ │ │ └── Breakpoints_v2.xcbkptlist
│ │ │ └── xcschemes
│ │ │ │ ├── xcschememanagement.plist
│ │ │ │ └── ToastDemo.xcscheme
│ │ └── nate.xcuserdatad
│ │ │ └── xcschemes
│ │ │ ├── xcschememanagement.plist
│ │ │ └── ToastDemo.xcscheme
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ ├── xcuserdata
│ │ │ ├── mac.xcuserdatad
│ │ │ │ └── UserInterfaceState.xcuserstate
│ │ │ ├── p2p.xcuserdatad
│ │ │ │ └── UserInterfaceState.xcuserstate
│ │ │ ├── mark.xcuserdatad
│ │ │ │ └── UserInterfaceState.xcuserstate
│ │ │ └── nate.xcuserdatad
│ │ │ │ └── UserInterfaceState.xcuserstate
│ │ └── xcshareddata
│ │ │ └── ToastDemo.xccheckout
│ └── project.pbxproj
├── ToastDemoTests
│ ├── Info.plist
│ └── ToastDemoTests.swift
└── Toast
│ └── HRToast+UIView.swift
├── ToastSwift.podspec
├── LICENSE
└── README.md
/Screenshots/image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rannie/Toast-Swift/HEAD/Screenshots/image.png
--------------------------------------------------------------------------------
/Screenshots/new_1.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rannie/Toast-Swift/HEAD/Screenshots/new_1.PNG
--------------------------------------------------------------------------------
/Screenshots/new_2.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rannie/Toast-Swift/HEAD/Screenshots/new_2.PNG
--------------------------------------------------------------------------------
/Screenshots/new_3.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rannie/Toast-Swift/HEAD/Screenshots/new_3.PNG
--------------------------------------------------------------------------------
/Screenshots/single.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rannie/Toast-Swift/HEAD/Screenshots/single.png
--------------------------------------------------------------------------------
/Screenshots/title.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rannie/Toast-Swift/HEAD/Screenshots/title.png
--------------------------------------------------------------------------------
/Screenshots/activity.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rannie/Toast-Swift/HEAD/Screenshots/activity.png
--------------------------------------------------------------------------------
/Screenshots/activity_message.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rannie/Toast-Swift/HEAD/Screenshots/activity_message.PNG
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo/Images.xcassets/swift-logo.imageset/swift-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rannie/Toast-Swift/HEAD/SwiftToastDemo/ToastDemo/Images.xcassets/swift-logo.imageset/swift-logo.png
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo.xcodeproj/xcuserdata/mac.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo.xcodeproj/xcuserdata/mark.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo.xcodeproj/xcuserdata/p2p.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo/Images.xcassets/small-image.imageset/exclamation-toast.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rannie/Toast-Swift/HEAD/SwiftToastDemo/ToastDemo/Images.xcassets/small-image.imageset/exclamation-toast.png
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo/Images.xcassets/small-image.imageset/exclamation-toast@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rannie/Toast-Swift/HEAD/SwiftToastDemo/ToastDemo/Images.xcassets/small-image.imageset/exclamation-toast@2x.png
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo/Images.xcassets/small-image.imageset/exclamation-toast@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rannie/Toast-Swift/HEAD/SwiftToastDemo/ToastDemo/Images.xcassets/small-image.imageset/exclamation-toast@3x.png
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rannie/Toast-Swift/HEAD/SwiftToastDemo/ToastDemo.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo.xcodeproj/project.xcworkspace/xcuserdata/p2p.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rannie/Toast-Swift/HEAD/SwiftToastDemo/ToastDemo.xcodeproj/project.xcworkspace/xcuserdata/p2p.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo.xcodeproj/project.xcworkspace/xcuserdata/mark.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rannie/Toast-Swift/HEAD/SwiftToastDemo/ToastDemo.xcodeproj/project.xcworkspace/xcuserdata/mark.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo.xcodeproj/project.xcworkspace/xcuserdata/nate.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rannie/Toast-Swift/HEAD/SwiftToastDemo/ToastDemo.xcodeproj/project.xcworkspace/xcuserdata/nate.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo/Images.xcassets/swift-logo.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "swift-logo.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // ToastDemo
4 | //
5 | // Created by Rannie on 14/7/6.
6 | // Copyright (c) 2014年 Rannie. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | @UIApplicationMain
12 | class AppDelegate: UIResponder, UIApplicationDelegate {
13 | var window: UIWindow?
14 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
15 | return true
16 | }
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/ToastSwift.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |s|
2 | s.name = "ToastSwift"
3 | s.version = "0.1.3"
4 | s.summary = "Toast view using swift."
5 | s.homepage = "https://github.com/Rannie/Toast-Swift"
6 | s.license = "MIT"
7 | s.author = "Hanran Liu"
8 | s.platform = :ios, "8.0"
9 | s.source = { :git => "https://github.com/Rannie/Toast-Swift.git", :tag => s.version }
10 | s.source_files = "Toast-Swift", "SwiftToastDemo/Toast/*.swift"
11 | s.framework = "UIKit"
12 | s.requires_arc = true
13 | end
14 |
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo/Images.xcassets/small-image.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "exclamation-toast.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "exclamation-toast@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "filename" : "exclamation-toast@3x.png",
16 | "scale" : "3x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo/Images.xcassets/LaunchImage.launchimage/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "orientation" : "portrait",
5 | "idiom" : "iphone",
6 | "extent" : "full-screen",
7 | "minimum-system-version" : "7.0",
8 | "scale" : "2x"
9 | },
10 | {
11 | "orientation" : "portrait",
12 | "idiom" : "iphone",
13 | "subtype" : "retina4",
14 | "extent" : "full-screen",
15 | "minimum-system-version" : "7.0",
16 | "scale" : "2x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | ToastDemo.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 04B641D51968DCF80000C251
16 |
17 | primary
18 |
19 |
20 | 04B641E71968DCF90000C251
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo.xcodeproj/xcuserdata/p2p.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | ToastDemo.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 04B641D51968DCF80000C251
16 |
17 | primary
18 |
19 |
20 | 04B641E71968DCF90000C251
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo.xcodeproj/xcuserdata/mark.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | ToastDemo.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 04B641D51968DCF80000C251
16 |
17 | primary
18 |
19 |
20 | 04B641E71968DCF90000C251
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo.xcodeproj/xcuserdata/nate.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | ToastDemo.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 04B641D51968DCF80000C251
16 |
17 | primary
18 |
19 |
20 | 04B641E71968DCF90000C251
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemoTests/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 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemoTests/ToastDemoTests.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ToastDemoTests.swift
3 | // ToastDemoTests
4 | //
5 | // Created by Rannie on 14/7/6.
6 | // Copyright (c) 2014年 Rannie. All rights reserved.
7 | //
8 |
9 | import XCTest
10 |
11 | class ToastDemoTests: XCTestCase {
12 |
13 | override func setUp() {
14 | super.setUp()
15 | // Put setup code here. This method is called before the invocation of each test method in the class.
16 | }
17 |
18 | override func tearDown() {
19 | // Put teardown code here. This method is called after the invocation of each test method in the class.
20 | super.tearDown()
21 | }
22 |
23 | func testExample() {
24 | // This is an example of a functional test case.
25 | XCTAssert(true, "Pass")
26 | }
27 |
28 | func testPerformanceExample() {
29 | // This is an example of a performance test case.
30 | self.measure() {
31 | // Put the code you want to measure the time of here.
32 | }
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "20x20",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "20x20",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "29x29",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "29x29",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "40x40",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "40x40",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "size" : "60x60",
36 | "scale" : "2x"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "size" : "60x60",
41 | "scale" : "3x"
42 | },
43 | {
44 | "idiom" : "ios-marketing",
45 | "size" : "1024x1024",
46 | "scale" : "1x"
47 | }
48 | ],
49 | "info" : {
50 | "version" : 1,
51 | "author" : "xcode"
52 | }
53 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2017 Hanran Liu
4 |
5 | Permission is hereby 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 without limitation 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 |
23 |
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo/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 | Launch Screen
27 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UIStatusBarStyle
34 | UIStatusBarStyleLightContent
35 | UIViewControllerBasedStatusBarAppearance
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo.xcodeproj/project.xcworkspace/xcshareddata/ToastDemo.xccheckout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDESourceControlProjectFavoriteDictionaryKey
6 |
7 | IDESourceControlProjectIdentifier
8 | FACD7E79-959B-4938-8F70-3F65D8A5E8E8
9 | IDESourceControlProjectName
10 | ToastDemo
11 | IDESourceControlProjectOriginsDictionary
12 |
13 | 887A4DAF38295A7621106664C13C6A5C89B19F59
14 | https://github.com/Rannie/Toast-Swift.git
15 |
16 | IDESourceControlProjectPath
17 | SwiftToastDemo/ToastDemo.xcodeproj
18 | IDESourceControlProjectRelativeInstallPathDictionary
19 |
20 | 887A4DAF38295A7621106664C13C6A5C89B19F59
21 | ../../..
22 |
23 | IDESourceControlProjectURL
24 | https://github.com/Rannie/Toast-Swift.git
25 | IDESourceControlProjectVersion
26 | 111
27 | IDESourceControlProjectWCCIdentifier
28 | 887A4DAF38295A7621106664C13C6A5C89B19F59
29 | IDESourceControlProjectWCConfigurations
30 |
31 |
32 | IDESourceControlRepositoryExtensionIdentifierKey
33 | public.vcs.git
34 | IDESourceControlWCCIdentifierKey
35 | 887A4DAF38295A7621106664C13C6A5C89B19F59
36 | IDESourceControlWCCName
37 | Toast-Swift
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Toast-Swift
2 | ===========
3 |
4 | Toast view using swift.
5 |
6 | 
7 | 
8 | 
9 |
10 |
11 | ### New Toast-Swift has been updated!
12 | ---------
13 |
14 | New Toast-Swift can compile with Swift 3.0.
15 |
16 | And u can set the theme color of the toast view.
17 |
18 | ### Install
19 | ---------
20 |
21 | download this repo and import "UIView+HRToast".
22 |
23 | ### Usage
24 | ---------
25 |
26 | 1. Set theme color (defalut is UIColor.blackColor())
27 |
28 | ```
29 | view.hr_setToastThemeColor(color: #ThemeColor)
30 | ```
31 |
32 | 2. Single toast view
33 |
34 | 
35 |
36 | ```
37 | view.makeToast(message: msg)
38 | ```
39 |
40 | 3. Toast with title
41 |
42 | 
43 |
44 | ```
45 | view.makeToast(message: msg, duration: duration, position: pos, title: subject)
46 | ```
47 |
48 | 4. Toast with image, title...
49 |
50 | 
51 |
52 | ```
53 | view.makeToast(message: msg, duration: duration, position: pos, title: subject, image: image)
54 | ```
55 |
56 | 5. Show and hide activity
57 |
58 | 
59 |
60 | ```
61 | view.makeToastActivity()
62 | view.hideToastActivity()
63 | ```
64 |
65 | 6. Show activity with message
66 |
67 | 
68 |
69 | ```
70 | view.makeToastActivityWithMessage(message: msg)
71 | ```
72 |
73 |
74 | ### LICENSE
75 | ---------
76 |
77 | The MIT License (MIT)
78 |
79 | Copyright (c) 2017 Hanran Liu
80 |
81 | Permission is hereby granted, free of charge, to any person obtaining a copy
82 | of this software and associated documentation files (the "Software"), to deal
83 | in the Software without restriction, including without limitation the rights
84 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
85 | copies of the Software, and to permit persons to whom the Software is
86 | furnished to do so, subject to the following conditions:
87 |
88 | The above copyright notice and this permission notice shall be included in all
89 | copies or substantial portions of the Software.
90 |
91 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
92 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
93 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
94 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
95 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
96 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
97 | SOFTWARE.
98 |
99 |
100 |
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo/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 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/ToastDemo.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
49 |
50 |
51 |
52 |
61 |
62 |
68 |
69 |
70 |
71 |
72 |
73 |
79 |
80 |
86 |
87 |
88 |
89 |
91 |
92 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo.xcodeproj/xcuserdata/p2p.xcuserdatad/xcschemes/ToastDemo.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
49 |
50 |
51 |
52 |
53 |
54 |
64 |
66 |
72 |
73 |
74 |
75 |
76 |
77 |
83 |
85 |
91 |
92 |
93 |
94 |
96 |
97 |
100 |
101 |
102 |
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo/Launch Screen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
27 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo.xcodeproj/xcuserdata/mark.xcuserdatad/xcschemes/ToastDemo.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
29 |
35 |
36 |
37 |
38 |
39 |
44 |
45 |
47 |
53 |
54 |
55 |
56 |
57 |
63 |
64 |
65 |
66 |
75 |
77 |
83 |
84 |
85 |
86 |
87 |
88 |
94 |
96 |
102 |
103 |
104 |
105 |
107 |
108 |
111 |
112 |
113 |
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo.xcodeproj/xcuserdata/nate.xcuserdatad/xcschemes/ToastDemo.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
29 |
35 |
36 |
37 |
38 |
39 |
44 |
45 |
47 |
53 |
54 |
55 |
56 |
57 |
63 |
64 |
65 |
66 |
75 |
77 |
83 |
84 |
85 |
86 |
87 |
88 |
94 |
96 |
102 |
103 |
104 |
105 |
107 |
108 |
111 |
112 |
113 |
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // ToastDemo
4 | //
5 | // Created by Rannie on 14/7/6.
6 | // Copyright (c) 2014年 Rannie. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | let ButtonWidth : CGFloat = 230.0
12 | let ButtonHeight : CGFloat = 40.0
13 | let MarginY : CGFloat = 10.0
14 | let MarginX = (UIScreen.main.bounds.size.width - ButtonWidth) / 2
15 | let ThemeColor = UIColor(red: 255/255.0, green: 163/255.0, blue: 0/255.0, alpha: 1.0)
16 |
17 | class ViewController: UIViewController {
18 |
19 | var presentWindow : UIWindow?
20 |
21 | override func viewDidLoad() {
22 | super.viewDidLoad()
23 | title = "Swift Toast"
24 | edgesForExtendedLayout = UIRectEdge()
25 | UIView.hr_setToastThemeColor(color: ThemeColor)
26 | presentWindow = UIApplication.shared.keyWindow
27 | setupButtons()
28 | }
29 |
30 | func setupButtons() {
31 | let singleToastBtn = quickAddButtonWithTitle("Single Toast", target: self, action: #selector(ViewController.handleSingleToastClicked(_:)))
32 | singleToastBtn.frame = CGRect(x: MarginX, y: 2*MarginY, width: ButtonWidth, height: ButtonHeight)
33 | view.addSubview(singleToastBtn)
34 |
35 | let longToastBtn = quickAddButtonWithTitle("Long Toast", target: self, action: #selector(ViewController.handleLongMessageToastClicked(_:)))
36 | longToastBtn.frame = CGRect(x: MarginX, y: 3*MarginY + ButtonHeight, width: ButtonWidth, height: ButtonHeight)
37 | view.addSubview(longToastBtn)
38 |
39 | let titleToastBtn = quickAddButtonWithTitle("Title Toast", target: self, action: #selector(ViewController.handleTitleToastClicked(_:)))
40 | titleToastBtn.frame = CGRect(x: MarginX, y: 4*MarginY + 2*ButtonHeight, width: ButtonWidth, height: ButtonHeight)
41 | view.addSubview(titleToastBtn)
42 |
43 | let largeImageToastBtn = quickAddButtonWithTitle("Large Image Toast", target: self, action: #selector(ViewController.handleLargeImageToastClicked(_:)))
44 | largeImageToastBtn.frame = CGRect(x: MarginX, y: 5*MarginY + 3*ButtonHeight, width: ButtonWidth, height: ButtonHeight)
45 | view.addSubview(largeImageToastBtn)
46 |
47 | let smallImageToastBtn = quickAddButtonWithTitle("Small Image Toast", target: self, action: #selector(ViewController.handleSmallImageToastClicked(_:)))
48 | smallImageToastBtn.frame = CGRect(x: MarginX, y: 6*MarginY + 4*ButtonHeight, width: ButtonWidth, height: ButtonHeight)
49 | view.addSubview(smallImageToastBtn)
50 |
51 | let showActivityBtn = quickAddButtonWithTitle("Show Activity", target: self, action: #selector(ViewController.showActivity))
52 | showActivityBtn.frame = CGRect(x: MarginX, y: 7*MarginY + 5*ButtonHeight, width: ButtonWidth, height: ButtonHeight)
53 | view.addSubview(showActivityBtn)
54 |
55 | let showMsgActivityBtn = quickAddButtonWithTitle("Show Activity With Message", target: self, action: #selector(ViewController.showActivityWithMessage))
56 | showMsgActivityBtn.frame = CGRect(x: MarginX, y: 8*MarginY + 6*ButtonHeight, width: ButtonWidth, height: ButtonHeight)
57 | view.addSubview(showMsgActivityBtn)
58 |
59 | let hideActivityBtn = quickAddButtonWithTitle("Hide Activity", target: self, action: #selector(ViewController.hideActivity))
60 | hideActivityBtn.frame = CGRect(x: MarginX, y: UIScreen.main.bounds.size.height - ButtonHeight - MarginY - 100, width: ButtonWidth, height: ButtonHeight)
61 | view.addSubview(hideActivityBtn)
62 | }
63 |
64 | override var preferredStatusBarStyle : UIStatusBarStyle {
65 | return UIStatusBarStyle.lightContent
66 | }
67 |
68 | // handle events
69 | @objc func handleSingleToastClicked(_ sender: UIButton) {
70 | presentWindow!.makeToast(message: sender.title(for: UIControlState())!)
71 | }
72 |
73 | @objc func handleLongMessageToastClicked(_ sender: UIButton) {
74 | view.makeToast(message: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum porttitor, nisl ut bibendum vestibulum, sem purus tempor arcu, quis aliquet diam eros non justo. Integer et est vel magna sagittis ultrices. Sed non convallis nisl, in fermentum odio. Sed quis leo congue, dapibus diam ut, dictum risus. Nullam feugiat erat eget magna bibendum, non luctus lacus mollis.", duration: 2, position: "bottom" as AnyObject)
75 | }
76 |
77 | @objc func handleTitleToastClicked(_ sender: UIButton) {
78 | view.makeToast(message: sender.title(for: UIControlState())!, duration: 2, position: HRToastPositionTop as AnyObject, title: "
")
79 | }
80 |
81 | @objc func handleLargeImageToastClicked(_ sender: UIButton) {
82 | let image = UIImage(named: "swift-logo.png")
83 | presentWindow!.makeToast(message: sender.title(for: UIControlState())!, duration: 2, position: "center" as AnyObject, title: "Large Image!", image: image!)
84 | }
85 |
86 | @objc func handleSmallImageToastClicked(_ sender: UIButton) {
87 | let image = UIImage(named: "small-image")
88 | presentWindow!.makeToast(message: sender.title(for: UIControlState())!, duration: 2, position: "center" as AnyObject, title: "Small Image!", image: image!)
89 | }
90 |
91 | @objc func showActivity() {
92 | presentWindow!.makeToastActivity()
93 | }
94 |
95 | @objc func showActivityWithMessage() {
96 | presentWindow!.makeToastActivity(message: "Loading...")
97 | }
98 |
99 | @objc func hideActivity() {
100 | presentWindow!.hideToastActivity()
101 | }
102 |
103 | override func touchesBegan(_ touches: Set, with event: UIEvent?) {
104 | presentWindow!.hideToastActivity()
105 | }
106 |
107 | // ui helper
108 | func quickAddButtonWithTitle(_ title: String, target: AnyObject!, action: Selector) -> UIButton {
109 | let ret = UIButton(type: .custom)
110 | ret.setTitle(title, for: UIControlState())
111 | ret.setTitleColor(ThemeColor, for: UIControlState())
112 | ret.addTarget(target, action: action, for: .touchUpInside)
113 | return ret
114 | }
115 |
116 | }
117 |
118 |
119 |
120 |
--------------------------------------------------------------------------------
/SwiftToastDemo/ToastDemo.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 047232671969078F00B0B8B1 /* HRToast+UIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 047232661969078F00B0B8B1 /* HRToast+UIView.swift */; };
11 | 04B641DC1968DCF80000C251 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04B641DB1968DCF80000C251 /* AppDelegate.swift */; };
12 | 04B641DE1968DCF80000C251 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04B641DD1968DCF80000C251 /* ViewController.swift */; };
13 | 04B641E11968DCF90000C251 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 04B641DF1968DCF90000C251 /* Main.storyboard */; };
14 | 04B641E31968DCF90000C251 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 04B641E21968DCF90000C251 /* Images.xcassets */; };
15 | 04B641EF1968DCF90000C251 /* ToastDemoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04B641EE1968DCF90000C251 /* ToastDemoTests.swift */; };
16 | B04C4DEF1C51EEC20095C9FA /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B04C4DEE1C51EEC20095C9FA /* Launch Screen.storyboard */; };
17 | /* End PBXBuildFile section */
18 |
19 | /* Begin PBXContainerItemProxy section */
20 | 04B641E91968DCF90000C251 /* PBXContainerItemProxy */ = {
21 | isa = PBXContainerItemProxy;
22 | containerPortal = 04B641CE1968DCF80000C251 /* Project object */;
23 | proxyType = 1;
24 | remoteGlobalIDString = 04B641D51968DCF80000C251;
25 | remoteInfo = ToastDemo;
26 | };
27 | /* End PBXContainerItemProxy section */
28 |
29 | /* Begin PBXFileReference section */
30 | 047232661969078F00B0B8B1 /* HRToast+UIView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "HRToast+UIView.swift"; sourceTree = ""; };
31 | 04B641D61968DCF80000C251 /* ToastDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ToastDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
32 | 04B641DA1968DCF80000C251 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
33 | 04B641DB1968DCF80000C251 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; };
34 | 04B641DD1968DCF80000C251 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; };
35 | 04B641E01968DCF90000C251 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
36 | 04B641E21968DCF90000C251 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; };
37 | 04B641E81968DCF90000C251 /* ToastDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ToastDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
38 | 04B641ED1968DCF90000C251 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
39 | 04B641EE1968DCF90000C251 /* ToastDemoTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToastDemoTests.swift; sourceTree = ""; };
40 | B04C4DEE1C51EEC20095C9FA /* Launch Screen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = "Launch Screen.storyboard"; sourceTree = ""; };
41 | /* End PBXFileReference section */
42 |
43 | /* Begin PBXFrameworksBuildPhase section */
44 | 04B641D31968DCF80000C251 /* Frameworks */ = {
45 | isa = PBXFrameworksBuildPhase;
46 | buildActionMask = 2147483647;
47 | files = (
48 | );
49 | runOnlyForDeploymentPostprocessing = 0;
50 | };
51 | 04B641E51968DCF90000C251 /* Frameworks */ = {
52 | isa = PBXFrameworksBuildPhase;
53 | buildActionMask = 2147483647;
54 | files = (
55 | );
56 | runOnlyForDeploymentPostprocessing = 0;
57 | };
58 | /* End PBXFrameworksBuildPhase section */
59 |
60 | /* Begin PBXGroup section */
61 | 047232651969078F00B0B8B1 /* Toast */ = {
62 | isa = PBXGroup;
63 | children = (
64 | 047232661969078F00B0B8B1 /* HRToast+UIView.swift */,
65 | );
66 | path = Toast;
67 | sourceTree = "";
68 | };
69 | 04B641CD1968DCF80000C251 = {
70 | isa = PBXGroup;
71 | children = (
72 | 047232651969078F00B0B8B1 /* Toast */,
73 | 04B641D81968DCF80000C251 /* ToastDemo */,
74 | 04B641EB1968DCF90000C251 /* ToastDemoTests */,
75 | 04B641D71968DCF80000C251 /* Products */,
76 | );
77 | sourceTree = "";
78 | };
79 | 04B641D71968DCF80000C251 /* Products */ = {
80 | isa = PBXGroup;
81 | children = (
82 | 04B641D61968DCF80000C251 /* ToastDemo.app */,
83 | 04B641E81968DCF90000C251 /* ToastDemoTests.xctest */,
84 | );
85 | name = Products;
86 | sourceTree = "";
87 | };
88 | 04B641D81968DCF80000C251 /* ToastDemo */ = {
89 | isa = PBXGroup;
90 | children = (
91 | 04B641DB1968DCF80000C251 /* AppDelegate.swift */,
92 | 04B641DD1968DCF80000C251 /* ViewController.swift */,
93 | 04B641D91968DCF80000C251 /* Supporting Files */,
94 | );
95 | path = ToastDemo;
96 | sourceTree = "";
97 | };
98 | 04B641D91968DCF80000C251 /* Supporting Files */ = {
99 | isa = PBXGroup;
100 | children = (
101 | 04B641E21968DCF90000C251 /* Images.xcassets */,
102 | 04B641DF1968DCF90000C251 /* Main.storyboard */,
103 | B04C4DEE1C51EEC20095C9FA /* Launch Screen.storyboard */,
104 | 04B641DA1968DCF80000C251 /* Info.plist */,
105 | );
106 | name = "Supporting Files";
107 | sourceTree = "";
108 | };
109 | 04B641EB1968DCF90000C251 /* ToastDemoTests */ = {
110 | isa = PBXGroup;
111 | children = (
112 | 04B641EE1968DCF90000C251 /* ToastDemoTests.swift */,
113 | 04B641EC1968DCF90000C251 /* Supporting Files */,
114 | );
115 | path = ToastDemoTests;
116 | sourceTree = "";
117 | };
118 | 04B641EC1968DCF90000C251 /* Supporting Files */ = {
119 | isa = PBXGroup;
120 | children = (
121 | 04B641ED1968DCF90000C251 /* Info.plist */,
122 | );
123 | name = "Supporting Files";
124 | sourceTree = "";
125 | };
126 | /* End PBXGroup section */
127 |
128 | /* Begin PBXNativeTarget section */
129 | 04B641D51968DCF80000C251 /* ToastDemo */ = {
130 | isa = PBXNativeTarget;
131 | buildConfigurationList = 04B641F21968DCF90000C251 /* Build configuration list for PBXNativeTarget "ToastDemo" */;
132 | buildPhases = (
133 | 04B641D21968DCF80000C251 /* Sources */,
134 | 04B641D31968DCF80000C251 /* Frameworks */,
135 | 04B641D41968DCF80000C251 /* Resources */,
136 | );
137 | buildRules = (
138 | );
139 | dependencies = (
140 | );
141 | name = ToastDemo;
142 | productName = ToastDemo;
143 | productReference = 04B641D61968DCF80000C251 /* ToastDemo.app */;
144 | productType = "com.apple.product-type.application";
145 | };
146 | 04B641E71968DCF90000C251 /* ToastDemoTests */ = {
147 | isa = PBXNativeTarget;
148 | buildConfigurationList = 04B641F51968DCF90000C251 /* Build configuration list for PBXNativeTarget "ToastDemoTests" */;
149 | buildPhases = (
150 | 04B641E41968DCF90000C251 /* Sources */,
151 | 04B641E51968DCF90000C251 /* Frameworks */,
152 | 04B641E61968DCF90000C251 /* Resources */,
153 | );
154 | buildRules = (
155 | );
156 | dependencies = (
157 | 04B641EA1968DCF90000C251 /* PBXTargetDependency */,
158 | );
159 | name = ToastDemoTests;
160 | productName = ToastDemoTests;
161 | productReference = 04B641E81968DCF90000C251 /* ToastDemoTests.xctest */;
162 | productType = "com.apple.product-type.bundle.unit-test";
163 | };
164 | /* End PBXNativeTarget section */
165 |
166 | /* Begin PBXProject section */
167 | 04B641CE1968DCF80000C251 /* Project object */ = {
168 | isa = PBXProject;
169 | attributes = {
170 | LastSwiftMigration = 0720;
171 | LastSwiftUpdateCheck = 0720;
172 | LastUpgradeCheck = 0720;
173 | ORGANIZATIONNAME = Rannie;
174 | TargetAttributes = {
175 | 04B641D51968DCF80000C251 = {
176 | CreatedOnToolsVersion = 6.0;
177 | LastSwiftMigration = 0810;
178 | };
179 | 04B641E71968DCF90000C251 = {
180 | CreatedOnToolsVersion = 6.0;
181 | LastSwiftMigration = 0810;
182 | TestTargetID = 04B641D51968DCF80000C251;
183 | };
184 | };
185 | };
186 | buildConfigurationList = 04B641D11968DCF80000C251 /* Build configuration list for PBXProject "ToastDemo" */;
187 | compatibilityVersion = "Xcode 3.2";
188 | developmentRegion = English;
189 | hasScannedForEncodings = 0;
190 | knownRegions = (
191 | en,
192 | Base,
193 | );
194 | mainGroup = 04B641CD1968DCF80000C251;
195 | productRefGroup = 04B641D71968DCF80000C251 /* Products */;
196 | projectDirPath = "";
197 | projectRoot = "";
198 | targets = (
199 | 04B641D51968DCF80000C251 /* ToastDemo */,
200 | 04B641E71968DCF90000C251 /* ToastDemoTests */,
201 | );
202 | };
203 | /* End PBXProject section */
204 |
205 | /* Begin PBXResourcesBuildPhase section */
206 | 04B641D41968DCF80000C251 /* Resources */ = {
207 | isa = PBXResourcesBuildPhase;
208 | buildActionMask = 2147483647;
209 | files = (
210 | B04C4DEF1C51EEC20095C9FA /* Launch Screen.storyboard in Resources */,
211 | 04B641E11968DCF90000C251 /* Main.storyboard in Resources */,
212 | 04B641E31968DCF90000C251 /* Images.xcassets in Resources */,
213 | );
214 | runOnlyForDeploymentPostprocessing = 0;
215 | };
216 | 04B641E61968DCF90000C251 /* Resources */ = {
217 | isa = PBXResourcesBuildPhase;
218 | buildActionMask = 2147483647;
219 | files = (
220 | );
221 | runOnlyForDeploymentPostprocessing = 0;
222 | };
223 | /* End PBXResourcesBuildPhase section */
224 |
225 | /* Begin PBXSourcesBuildPhase section */
226 | 04B641D21968DCF80000C251 /* Sources */ = {
227 | isa = PBXSourcesBuildPhase;
228 | buildActionMask = 2147483647;
229 | files = (
230 | 047232671969078F00B0B8B1 /* HRToast+UIView.swift in Sources */,
231 | 04B641DE1968DCF80000C251 /* ViewController.swift in Sources */,
232 | 04B641DC1968DCF80000C251 /* AppDelegate.swift in Sources */,
233 | );
234 | runOnlyForDeploymentPostprocessing = 0;
235 | };
236 | 04B641E41968DCF90000C251 /* Sources */ = {
237 | isa = PBXSourcesBuildPhase;
238 | buildActionMask = 2147483647;
239 | files = (
240 | 04B641EF1968DCF90000C251 /* ToastDemoTests.swift in Sources */,
241 | );
242 | runOnlyForDeploymentPostprocessing = 0;
243 | };
244 | /* End PBXSourcesBuildPhase section */
245 |
246 | /* Begin PBXTargetDependency section */
247 | 04B641EA1968DCF90000C251 /* PBXTargetDependency */ = {
248 | isa = PBXTargetDependency;
249 | target = 04B641D51968DCF80000C251 /* ToastDemo */;
250 | targetProxy = 04B641E91968DCF90000C251 /* PBXContainerItemProxy */;
251 | };
252 | /* End PBXTargetDependency section */
253 |
254 | /* Begin PBXVariantGroup section */
255 | 04B641DF1968DCF90000C251 /* Main.storyboard */ = {
256 | isa = PBXVariantGroup;
257 | children = (
258 | 04B641E01968DCF90000C251 /* Base */,
259 | );
260 | name = Main.storyboard;
261 | sourceTree = "";
262 | };
263 | /* End PBXVariantGroup section */
264 |
265 | /* Begin XCBuildConfiguration section */
266 | 04B641F01968DCF90000C251 /* Debug */ = {
267 | isa = XCBuildConfiguration;
268 | buildSettings = {
269 | ALWAYS_SEARCH_USER_PATHS = NO;
270 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
271 | CLANG_CXX_LIBRARY = "libc++";
272 | CLANG_ENABLE_MODULES = YES;
273 | CLANG_ENABLE_OBJC_ARC = YES;
274 | CLANG_WARN_BOOL_CONVERSION = YES;
275 | CLANG_WARN_CONSTANT_CONVERSION = YES;
276 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
277 | CLANG_WARN_EMPTY_BODY = YES;
278 | CLANG_WARN_ENUM_CONVERSION = YES;
279 | CLANG_WARN_INT_CONVERSION = YES;
280 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
281 | CLANG_WARN_UNREACHABLE_CODE = YES;
282 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
283 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
284 | COPY_PHASE_STRIP = NO;
285 | ENABLE_STRICT_OBJC_MSGSEND = YES;
286 | ENABLE_TESTABILITY = YES;
287 | GCC_C_LANGUAGE_STANDARD = gnu99;
288 | GCC_DYNAMIC_NO_PIC = NO;
289 | GCC_OPTIMIZATION_LEVEL = 0;
290 | GCC_PREPROCESSOR_DEFINITIONS = (
291 | "DEBUG=1",
292 | "$(inherited)",
293 | );
294 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
295 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
296 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
297 | GCC_WARN_UNDECLARED_SELECTOR = YES;
298 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
299 | GCC_WARN_UNUSED_FUNCTION = YES;
300 | GCC_WARN_UNUSED_VARIABLE = YES;
301 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
302 | METAL_ENABLE_DEBUG_INFO = YES;
303 | ONLY_ACTIVE_ARCH = YES;
304 | SDKROOT = iphoneos;
305 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
306 | };
307 | name = Debug;
308 | };
309 | 04B641F11968DCF90000C251 /* Release */ = {
310 | isa = XCBuildConfiguration;
311 | buildSettings = {
312 | ALWAYS_SEARCH_USER_PATHS = NO;
313 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
314 | CLANG_CXX_LIBRARY = "libc++";
315 | CLANG_ENABLE_MODULES = YES;
316 | CLANG_ENABLE_OBJC_ARC = YES;
317 | CLANG_WARN_BOOL_CONVERSION = YES;
318 | CLANG_WARN_CONSTANT_CONVERSION = YES;
319 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
320 | CLANG_WARN_EMPTY_BODY = YES;
321 | CLANG_WARN_ENUM_CONVERSION = YES;
322 | CLANG_WARN_INT_CONVERSION = YES;
323 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
324 | CLANG_WARN_UNREACHABLE_CODE = YES;
325 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
326 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
327 | COPY_PHASE_STRIP = YES;
328 | ENABLE_NS_ASSERTIONS = NO;
329 | ENABLE_STRICT_OBJC_MSGSEND = YES;
330 | GCC_C_LANGUAGE_STANDARD = gnu99;
331 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
332 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
333 | GCC_WARN_UNDECLARED_SELECTOR = YES;
334 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
335 | GCC_WARN_UNUSED_FUNCTION = YES;
336 | GCC_WARN_UNUSED_VARIABLE = YES;
337 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
338 | METAL_ENABLE_DEBUG_INFO = NO;
339 | SDKROOT = iphoneos;
340 | VALIDATE_PRODUCT = YES;
341 | };
342 | name = Release;
343 | };
344 | 04B641F31968DCF90000C251 /* Debug */ = {
345 | isa = XCBuildConfiguration;
346 | buildSettings = {
347 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
348 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
349 | INFOPLIST_FILE = ToastDemo/Info.plist;
350 | IPHONEOS_DEPLOYMENT_TARGET = 9.0;
351 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
352 | PRODUCT_BUNDLE_IDENTIFIER = "com.rannie.${PRODUCT_NAME:rfc1034identifier}";
353 | PRODUCT_NAME = "$(TARGET_NAME)";
354 | SWIFT_VERSION = 4.0;
355 | };
356 | name = Debug;
357 | };
358 | 04B641F41968DCF90000C251 /* Release */ = {
359 | isa = XCBuildConfiguration;
360 | buildSettings = {
361 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
362 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
363 | INFOPLIST_FILE = ToastDemo/Info.plist;
364 | IPHONEOS_DEPLOYMENT_TARGET = 9.0;
365 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
366 | PRODUCT_BUNDLE_IDENTIFIER = "com.rannie.${PRODUCT_NAME:rfc1034identifier}";
367 | PRODUCT_NAME = "$(TARGET_NAME)";
368 | SWIFT_VERSION = 4.0;
369 | };
370 | name = Release;
371 | };
372 | 04B641F61968DCF90000C251 /* Debug */ = {
373 | isa = XCBuildConfiguration;
374 | buildSettings = {
375 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/ToastDemo.app/ToastDemo";
376 | FRAMEWORK_SEARCH_PATHS = (
377 | "$(SDKROOT)/Developer/Library/Frameworks",
378 | "$(inherited)",
379 | );
380 | GCC_PREPROCESSOR_DEFINITIONS = (
381 | "DEBUG=1",
382 | "$(inherited)",
383 | );
384 | INFOPLIST_FILE = ToastDemoTests/Info.plist;
385 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
386 | METAL_ENABLE_DEBUG_INFO = YES;
387 | PRODUCT_BUNDLE_IDENTIFIER = "com.rannie.${PRODUCT_NAME:rfc1034identifier}";
388 | PRODUCT_NAME = "$(TARGET_NAME)";
389 | SWIFT_VERSION = 4.0;
390 | TEST_HOST = "$(BUNDLE_LOADER)";
391 | };
392 | name = Debug;
393 | };
394 | 04B641F71968DCF90000C251 /* Release */ = {
395 | isa = XCBuildConfiguration;
396 | buildSettings = {
397 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/ToastDemo.app/ToastDemo";
398 | FRAMEWORK_SEARCH_PATHS = (
399 | "$(SDKROOT)/Developer/Library/Frameworks",
400 | "$(inherited)",
401 | );
402 | INFOPLIST_FILE = ToastDemoTests/Info.plist;
403 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
404 | METAL_ENABLE_DEBUG_INFO = NO;
405 | PRODUCT_BUNDLE_IDENTIFIER = "com.rannie.${PRODUCT_NAME:rfc1034identifier}";
406 | PRODUCT_NAME = "$(TARGET_NAME)";
407 | SWIFT_VERSION = 4.0;
408 | TEST_HOST = "$(BUNDLE_LOADER)";
409 | };
410 | name = Release;
411 | };
412 | /* End XCBuildConfiguration section */
413 |
414 | /* Begin XCConfigurationList section */
415 | 04B641D11968DCF80000C251 /* Build configuration list for PBXProject "ToastDemo" */ = {
416 | isa = XCConfigurationList;
417 | buildConfigurations = (
418 | 04B641F01968DCF90000C251 /* Debug */,
419 | 04B641F11968DCF90000C251 /* Release */,
420 | );
421 | defaultConfigurationIsVisible = 0;
422 | defaultConfigurationName = Release;
423 | };
424 | 04B641F21968DCF90000C251 /* Build configuration list for PBXNativeTarget "ToastDemo" */ = {
425 | isa = XCConfigurationList;
426 | buildConfigurations = (
427 | 04B641F31968DCF90000C251 /* Debug */,
428 | 04B641F41968DCF90000C251 /* Release */,
429 | );
430 | defaultConfigurationIsVisible = 0;
431 | defaultConfigurationName = Release;
432 | };
433 | 04B641F51968DCF90000C251 /* Build configuration list for PBXNativeTarget "ToastDemoTests" */ = {
434 | isa = XCConfigurationList;
435 | buildConfigurations = (
436 | 04B641F61968DCF90000C251 /* Debug */,
437 | 04B641F71968DCF90000C251 /* Release */,
438 | );
439 | defaultConfigurationIsVisible = 0;
440 | defaultConfigurationName = Release;
441 | };
442 | /* End XCConfigurationList section */
443 | };
444 | rootObject = 04B641CE1968DCF80000C251 /* Project object */;
445 | }
446 |
--------------------------------------------------------------------------------
/SwiftToastDemo/Toast/HRToast+UIView.swift:
--------------------------------------------------------------------------------
1 | //
2 | // HRToast + UIView.swift
3 | // ToastDemo
4 | //
5 | // Created by Rannie on 14/7/6.
6 | // Copyright (c) 2014年 Rannie. All rights reserved.
7 | // https://github.com/Rannie/Toast-Swift
8 | //
9 |
10 | import UIKit
11 |
12 | /*
13 | * Infix overload method
14 | */
15 | func /(lhs: CGFloat, rhs: Int) -> CGFloat {
16 | return lhs / CGFloat(rhs)
17 | }
18 |
19 | /*
20 | * Toast Config
21 | */
22 | public struct HRToastConfig {
23 | var HRToastDefaultDuration = 2.0
24 | var HRToastFadeDuration = 0.2
25 | var HRToastHorizontalMargin : CGFloat = 10.0
26 | var HRToastVerticalMargin : CGFloat = 10.0
27 |
28 | var HRToastPositionVerticalOffset : CGFloat = 10.0
29 | var HRToastPosition = HRToastPositionDefault
30 | var HRToastzPosition : CGFloat = 2.0
31 |
32 | // activity
33 | var HRToastActivityWidth : CGFloat = 100.0
34 | var HRToastActivityHeight : CGFloat = 100.0
35 | var HRToastActivityPositionDefault = "center"
36 |
37 | // image size
38 | var HRToastImageViewWidth : CGFloat = 80.0
39 | var HRToastImageViewHeight: CGFloat = 80.0
40 |
41 | // label setting
42 | var HRToastMaxWidth : CGFloat = 0.8; // 80% of parent view width
43 | var HRToastMaxHeight : CGFloat = 0.8;
44 | var HRToastFontSize : CGFloat = 16.0
45 | var HRToastMaxTitleLines = 0
46 | var HRToastMaxMessageLines = 0
47 |
48 | // shadow appearance
49 | var HRToastShadowOpacity : CGFloat = 0.8
50 | var HRToastShadowRadius : CGFloat = 6.0
51 | var HRToastShadowOffset : CGSize = CGSize(width: CGFloat(4.0), height: CGFloat(4.0))
52 |
53 | var HRToastOpacity : CGFloat = 0.9
54 | var HRToastCornerRadius : CGFloat = 10.0
55 |
56 | /*
57 | * Custom Config
58 | */
59 | var HRToastHidesOnTap = true
60 | var HRToastDisplayShadow = true
61 |
62 | public init() {}
63 | }
64 |
65 | let HRToastPositionDefault = "bottom"
66 | let HRToastPositionTop = "top"
67 | let HRToastPositionCenter = "center"
68 |
69 | var HRToastActivityView: UnsafePointer? = nil
70 | var HRToastTimer: UnsafePointer? = nil
71 | var HRToastView: UnsafePointer? = nil
72 | var HRToastThemeColor : UnsafePointer? = nil
73 | var HRToastTitleFontName: UnsafePointer? = nil
74 | var HRToastFontName: UnsafePointer? = nil
75 | var HRToastFontColor: UnsafePointer? = nil
76 |
77 | let defaults = HRToastConfig()
78 |
79 | //HRToast (UIView + Toast using Swift)
80 |
81 | public extension UIView {
82 |
83 | /*
84 | * public methods
85 | */
86 | class func hr_setToastThemeColor(color: UIColor) {
87 | objc_setAssociatedObject(self, &HRToastThemeColor, color, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
88 | }
89 |
90 | class func hr_toastThemeColor() -> UIColor {
91 | var color = objc_getAssociatedObject(self, &HRToastThemeColor) as! UIColor?
92 | if color == nil {
93 | color = UIColor.black
94 | UIView.hr_setToastThemeColor(color: color!)
95 | }
96 | return color!
97 | }
98 |
99 | class func hr_setToastTitleFontName(fontName: String) {
100 | objc_setAssociatedObject(self, &HRToastTitleFontName, fontName, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
101 | }
102 |
103 | class func hr_toastTitleFontName() -> String {
104 | var name = objc_getAssociatedObject(self, &HRToastTitleFontName) as! String?
105 | if name == nil {
106 | let font = UIFont.systemFont(ofSize: 12.0)
107 | name = font.fontName
108 | UIView.hr_setToastTitleFontName(fontName: name!)
109 | }
110 |
111 | return name!
112 | }
113 |
114 | class func hr_setToastFontName(fontName: String) {
115 | objc_setAssociatedObject(self, &HRToastFontName, fontName, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
116 | }
117 |
118 | class func hr_toastFontName() -> String {
119 | var name = objc_getAssociatedObject(self, &HRToastFontName) as! String?
120 | if name == nil {
121 | let font = UIFont.systemFont(ofSize: 12.0)
122 | name = font.fontName
123 | UIView.hr_setToastFontName(fontName: name!)
124 | }
125 |
126 | return name!
127 | }
128 |
129 | class func hr_setToastFontColor(color: UIColor) {
130 | objc_setAssociatedObject(self, &HRToastFontColor, color, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
131 | }
132 |
133 | class func hr_toastFontColor() -> UIColor {
134 | var color = objc_getAssociatedObject(self, &HRToastFontColor) as! UIColor?
135 | if color == nil {
136 | color = UIColor.white
137 | UIView.hr_setToastFontColor(color: color!)
138 | }
139 |
140 | return color!
141 | }
142 |
143 | func makeToast(message msg: String, withConfiguration config: HRToastConfig = HRToastConfig()) {
144 | makeToast(message: msg, duration: config.HRToastDefaultDuration, position: config.HRToastPosition as AnyObject, withConfiguration: config)
145 | }
146 |
147 | func makeToast(message msg: String, duration: Double, position: AnyObject, withConfiguration config: HRToastConfig = HRToastConfig()) {
148 | let toast = self.viewForMessage(msg, title: nil, image: nil, withConfiguration: config)
149 | showToast(toast: toast!, duration: duration, position: position, withConfiguration: config)
150 | }
151 |
152 | func makeToast(message msg: String, duration: Double, position: AnyObject, title: String, withConfiguration config: HRToastConfig = HRToastConfig()) {
153 | let toast = self.viewForMessage(msg, title: title, image: nil, withConfiguration: config)
154 | showToast(toast: toast!, duration: duration, position: position, withConfiguration: config)
155 | }
156 |
157 | func makeToast(message msg: String, duration: Double, position: AnyObject, image: UIImage, withConfiguration config: HRToastConfig = HRToastConfig()) {
158 | let toast = self.viewForMessage(msg, title: nil, image: image, withConfiguration: config)
159 | showToast(toast: toast!, duration: duration, position: position, withConfiguration: config)
160 | }
161 |
162 | func makeToast(message msg: String, duration: Double, position: AnyObject, title: String, image: UIImage, withConfiguration config: HRToastConfig = HRToastConfig()) {
163 | let toast = self.viewForMessage(msg, title: title, image: image, withConfiguration: config)
164 | showToast(toast: toast!, duration: duration, position: position, withConfiguration: config)
165 | }
166 |
167 | func showToast(toast: UIView, withConfiguration config: HRToastConfig = HRToastConfig()) {
168 | showToast(toast: toast, duration: config.HRToastDefaultDuration, position: config.HRToastPosition as AnyObject, withConfiguration: config)
169 | }
170 |
171 | fileprivate func showToast(toast: UIView, duration: Double, position: AnyObject, withConfiguration config: HRToastConfig) {
172 | let existToast = objc_getAssociatedObject(self, &HRToastView) as! UIView?
173 | if existToast != nil {
174 | if let timer: Timer = objc_getAssociatedObject(existToast as Any, &HRToastTimer) as? Timer {
175 | timer.invalidate()
176 | }
177 | hideToast(toast: existToast!, force: false, withConfiguration: config);
178 | print("hide exist!")
179 | }
180 |
181 | toast.alpha = 0.0
182 |
183 | if config.HRToastHidesOnTap {
184 | let tapRecognizer = UITapGestureRecognizer(target: toast, action: #selector(UIView.handleToastTapped(_:)))
185 | toast.addGestureRecognizer(tapRecognizer)
186 | toast.isUserInteractionEnabled = true;
187 | toast.isExclusiveTouch = true;
188 | }
189 |
190 | addSubview(toast)
191 | let sidePadding = self.bounds.width * (1 - config.HRToastMaxWidth) / 2
192 | toast.leftAnchor.constraint(equalTo: self.leftAnchor, constant: sidePadding).isActive = true
193 | toast.rightAnchor.constraint(equalTo: self.rightAnchor, constant: -sidePadding).isActive = true
194 |
195 | let desiredSize = toast.systemLayoutSizeFitting(UILayoutFittingCompressedSize)
196 | toast.heightAnchor.constraint(equalToConstant: desiredSize.height).isActive = true
197 |
198 | let yPosition = yPositionForToastPosition(position, toastSize: desiredSize, withConfiguration: config)
199 | toast.centerYAnchor.constraint(equalTo: self.topAnchor, constant: yPosition).isActive = true
200 | objc_setAssociatedObject(self, &HRToastView, toast, .OBJC_ASSOCIATION_RETAIN)
201 |
202 | UIView.animate(withDuration: config.HRToastFadeDuration,
203 | delay: 0.0, options: ([.curveEaseOut, .allowUserInteraction]),
204 | animations: {
205 | toast.alpha = 1.0
206 | },
207 | completion: { (finished: Bool) in
208 | let timer = Timer.scheduledTimer(timeInterval: duration, target: self, selector: #selector(UIView.toastTimerDidFinish(_:)), userInfo: toast, repeats: false)
209 | objc_setAssociatedObject(toast, &HRToastTimer, timer, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
210 | })
211 | }
212 |
213 | func makeToastActivity(withConfiguration config: HRToastConfig = HRToastConfig()) {
214 | makeToastActivity(position: config.HRToastActivityPositionDefault as AnyObject, withConfiguration: config)
215 | }
216 |
217 | func makeToastActivity(message msg: String, withConfiguration config: HRToastConfig = HRToastConfig()){
218 | makeToastActivity(position: config.HRToastActivityPositionDefault as AnyObject, message: msg, withConfiguration: config)
219 | }
220 |
221 | fileprivate func makeToastActivity(position pos: AnyObject, message msg: String = "", withConfiguration config: HRToastConfig) {
222 | let existingActivityView: UIView? = objc_getAssociatedObject(self, &HRToastActivityView) as? UIView
223 | if existingActivityView != nil { return }
224 |
225 | let activityView = UIView(frame: CGRect(x: 0, y: 0, width: config.HRToastActivityWidth, height: config.HRToastActivityHeight))
226 | activityView.layer.cornerRadius = config.HRToastCornerRadius
227 |
228 | activityView.center = self.centerPointForPosition(pos, toast: activityView, withConfiguration: config)
229 | activityView.backgroundColor = UIView.hr_toastThemeColor().withAlphaComponent(config.HRToastOpacity)
230 | activityView.alpha = 0.0
231 | activityView.autoresizingMask = ([.flexibleLeftMargin, .flexibleTopMargin, .flexibleRightMargin, .flexibleBottomMargin])
232 |
233 | if config.HRToastDisplayShadow {
234 | activityView.layer.shadowColor = UIView.hr_toastThemeColor().cgColor
235 | activityView.layer.shadowOpacity = Float(config.HRToastShadowOpacity)
236 | activityView.layer.shadowRadius = config.HRToastShadowRadius
237 | activityView.layer.shadowOffset = config.HRToastShadowOffset
238 | }
239 |
240 | let activityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: .whiteLarge)
241 | activityIndicatorView.center = CGPoint(x: activityView.bounds.size.width / 2, y: activityView.bounds.size.height / 2)
242 | activityView.addSubview(activityIndicatorView)
243 | activityIndicatorView.startAnimating()
244 |
245 | if (!msg.isEmpty){
246 | activityIndicatorView.frame.origin.y -= 10
247 | let activityMessageLabel = UILabel(frame: CGRect(x: activityView.bounds.origin.x, y: (activityIndicatorView.frame.origin.y + activityIndicatorView.frame.size.height + 10), width: activityView.bounds.size.width, height: 20))
248 | activityMessageLabel.textColor = UIView.hr_toastFontColor()
249 | activityMessageLabel.font = (msg.characters.count<=10) ? UIFont(name:UIView.hr_toastFontName(), size: 16) : UIFont(name:UIView.hr_toastFontName(), size: 13)
250 | activityMessageLabel.textAlignment = .center
251 | activityMessageLabel.text = msg
252 | activityView.addSubview(activityMessageLabel)
253 | }
254 |
255 | addSubview(activityView)
256 |
257 | // associate activity view with self
258 | objc_setAssociatedObject(self, &HRToastActivityView, activityView, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
259 |
260 | UIView.animate(withDuration: config.HRToastFadeDuration,
261 | delay: 0.0,
262 | options: UIViewAnimationOptions.curveEaseOut,
263 | animations: {
264 | activityView.alpha = 1.0
265 | },
266 | completion: nil)
267 | }
268 |
269 | func hideToastActivity(withConfiguration config: HRToastConfig = HRToastConfig()) {
270 | let existingActivityView = objc_getAssociatedObject(self, &HRToastActivityView) as! UIView?
271 | if existingActivityView == nil { return }
272 | UIView.animate(withDuration: config.HRToastFadeDuration,
273 | delay: 0.0,
274 | options: UIViewAnimationOptions.curveEaseOut,
275 | animations: {
276 | existingActivityView!.alpha = 0.0
277 | },
278 | completion: { (finished: Bool) in
279 | existingActivityView!.removeFromSuperview()
280 | objc_setAssociatedObject(self, &HRToastActivityView, nil, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
281 | })
282 | }
283 |
284 | /*
285 | * private methods (helper)
286 | */
287 | func hideToast(toast: UIView) {
288 | hideToast(toast: toast, force: false, withConfiguration: HRToastConfig());
289 | }
290 |
291 | func hideToast(toast: UIView, force: Bool, withConfiguration config: HRToastConfig) {
292 | let completeClosure = { (finish: Bool) -> () in
293 | toast.removeFromSuperview()
294 | objc_setAssociatedObject(self, &HRToastTimer, nil, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
295 | }
296 |
297 | if force {
298 | completeClosure(true)
299 | } else {
300 | UIView.animate(withDuration: config.HRToastFadeDuration,
301 | delay: 0.0,
302 | options: ([.curveEaseIn, .beginFromCurrentState]),
303 | animations: {
304 | toast.alpha = 0.0
305 | },
306 | completion:completeClosure)
307 | }
308 | }
309 |
310 | @objc func toastTimerDidFinish(_ timer: Timer) {
311 | hideToast(toast: timer.userInfo as! UIView)
312 | }
313 |
314 | @objc func handleToastTapped(_ recognizer: UITapGestureRecognizer) {
315 | let timer = objc_getAssociatedObject(self, &HRToastTimer) as? Timer
316 |
317 | if let timer = timer {
318 | timer.invalidate()
319 | }
320 |
321 | hideToast(toast: recognizer.view!)
322 | }
323 |
324 | fileprivate func yPositionForToastPosition(_ position: AnyObject, toastSize: CGSize, withConfiguration config: HRToastConfig) -> CGFloat {
325 | let viewSize = self.bounds.size
326 |
327 | if position is String {
328 | if position.lowercased == HRToastPositionTop {
329 | return toastSize.height/2 + config.HRToastPositionVerticalOffset
330 | } else if position.lowercased == HRToastPositionDefault {
331 | return viewSize.height - toastSize.height/2 - config.HRToastPositionVerticalOffset
332 | } else if position.lowercased == HRToastPositionCenter {
333 | return viewSize.height/2
334 | }
335 | } else if position is CGFloat {
336 | return position as! CGFloat
337 | }
338 |
339 | print("[Toast-Swift]: Warning! Invalid position for toast.")
340 | return viewSize.height/2
341 | }
342 |
343 | fileprivate func centerPointForPosition(_ position: AnyObject, toast: UIView, withConfiguration config: HRToastConfig) -> CGPoint {
344 | if position is String {
345 | let toastSize = toast.bounds.size
346 | let viewSize = self.bounds.size
347 | if position.lowercased == HRToastPositionTop {
348 | return CGPoint(x: viewSize.width/2, y: toastSize.height/2 + config.HRToastVerticalMargin)
349 | } else if position.lowercased == HRToastPositionDefault {
350 | return CGPoint(x: viewSize.width/2, y: viewSize.height - toastSize.height/2 - config.HRToastVerticalMargin)
351 | } else if position.lowercased == HRToastPositionCenter {
352 | return CGPoint(x: viewSize.width/2, y: viewSize.height/2)
353 | }
354 | } else if position is NSValue {
355 | return position.cgPointValue
356 | }
357 |
358 | print("[Toast-Swift]: Warning! Invalid position for toast.")
359 | return self.centerPointForPosition(config.HRToastPosition as AnyObject, toast: toast, withConfiguration: config)
360 | }
361 |
362 | fileprivate func viewForMessage(_ msg: String?, title: String?, image: UIImage?, withConfiguration config: HRToastConfig) -> UIView? {
363 | if msg == nil && title == nil && image == nil { return nil }
364 |
365 | let someTextBeingShown = (msg != nil || title != nil)
366 | let wrapperView = createInitialView(withConfiguration: config)
367 | let contentsStackView = addContentsStackView(toWrapperView: wrapperView, withConfiguration: config)
368 |
369 | if let image = image {
370 | addImage(image, toStackView: contentsStackView)
371 | }
372 |
373 | if someTextBeingShown {
374 | addMessage(msg, andTitle: title, toStackView: contentsStackView, withConfiguration: config)
375 | }
376 |
377 | return wrapperView
378 | }
379 |
380 | fileprivate func createInitialView(withConfiguration config: HRToastConfig) -> UIView {
381 | let initialView = UIView()
382 | initialView.translatesAutoresizingMaskIntoConstraints = false
383 | initialView.layer.cornerRadius = config.HRToastCornerRadius
384 | initialView.layer.zPosition = config.HRToastzPosition
385 | initialView.backgroundColor = UIView.hr_toastThemeColor().withAlphaComponent(config.HRToastOpacity)
386 |
387 | if config.HRToastDisplayShadow {
388 | initialView.layer.shadowColor = UIView.hr_toastThemeColor().cgColor
389 | initialView.layer.shadowOpacity = Float(config.HRToastShadowOpacity)
390 | initialView.layer.shadowRadius = config.HRToastShadowRadius
391 | initialView.layer.shadowOffset = config.HRToastShadowOffset
392 | }
393 |
394 | return initialView
395 | }
396 |
397 | fileprivate func addContentsStackView(toWrapperView wrapperView: UIView, withConfiguration config: HRToastConfig) -> UIStackView {
398 | let stackView = UIStackView()
399 | stackView.translatesAutoresizingMaskIntoConstraints = false
400 | stackView.backgroundColor = UIColor.clear
401 | stackView.axis = .horizontal
402 | stackView.alignment = .center
403 | stackView.distribution = .fill
404 | stackView.spacing = config.HRToastVerticalMargin
405 | stackView.setContentHuggingPriority(UILayoutPriority(rawValue: 1000), for: .vertical)
406 | stackView.setContentHuggingPriority(UILayoutPriority(rawValue: 1000), for: .horizontal)
407 |
408 | wrapperView.addSubview(stackView)
409 | stackView.centerXAnchor.constraint(equalTo: wrapperView.centerXAnchor).isActive = true
410 | let leftSideConstraint = stackView.leftAnchor.constraint(greaterThanOrEqualTo: wrapperView.leftAnchor, constant: config.HRToastHorizontalMargin)
411 | leftSideConstraint.priority = UILayoutPriority(rawValue: 1000)
412 | leftSideConstraint.isActive = true
413 | let rightSideConstraint = stackView.rightAnchor.constraint(lessThanOrEqualTo: wrapperView.rightAnchor, constant: -config.HRToastHorizontalMargin)
414 | rightSideConstraint.priority = UILayoutPriority(rawValue: 1000)
415 | rightSideConstraint.isActive = true
416 | let leftSideEqualConstraint = stackView.leftAnchor.constraint(equalTo: wrapperView.leftAnchor, constant: config.HRToastHorizontalMargin)
417 | leftSideEqualConstraint.priority = UILayoutPriority(rawValue: 250)
418 | leftSideEqualConstraint.isActive = true
419 | let rightSideEqualConstraint = stackView.rightAnchor.constraint(equalTo: wrapperView.rightAnchor, constant: -config.HRToastHorizontalMargin)
420 | rightSideEqualConstraint.priority = UILayoutPriority(rawValue: 250)
421 | rightSideEqualConstraint.isActive = true
422 | stackView.topAnchor.constraint(equalTo: wrapperView.topAnchor, constant: config.HRToastVerticalMargin).isActive = true
423 | stackView.bottomAnchor.constraint(equalTo: wrapperView.bottomAnchor, constant: -config.HRToastVerticalMargin).isActive = true
424 |
425 | return stackView
426 | }
427 |
428 | fileprivate func addImage(_ image: UIImage, toStackView stackView: UIStackView) {
429 | let imageView = UIImageView(image: image)
430 | imageView.translatesAutoresizingMaskIntoConstraints = false
431 | imageView.setContentHuggingPriority(UILayoutPriority(rawValue: 1000), for: .horizontal)
432 | imageView.setContentHuggingPriority(UILayoutPriority(rawValue: 1000), for: .vertical)
433 |
434 | stackView.addArrangedSubview(imageView)
435 | }
436 |
437 | fileprivate func addMessage(_ msg: String?, andTitle title: String?, toStackView parentStackView: UIStackView, withConfiguration config: HRToastConfig) {
438 | let stackView = UIStackView()
439 | stackView.translatesAutoresizingMaskIntoConstraints = false
440 | stackView.backgroundColor = UIColor.clear
441 | stackView.axis = .vertical
442 | stackView.alignment = .fill
443 | stackView.distribution = .fill
444 | stackView.spacing = config.HRToastVerticalMargin
445 | parentStackView.addArrangedSubview(stackView)
446 |
447 | stackView.setContentHuggingPriority(UILayoutPriority(rawValue: 1000), for: .vertical)
448 | stackView.setContentHuggingPriority(UILayoutPriority(rawValue: 1000), for: .horizontal)
449 |
450 | if let title = title {
451 | let titleLabel = UILabel()
452 | titleLabel.translatesAutoresizingMaskIntoConstraints = false
453 | titleLabel.numberOfLines = config.HRToastMaxTitleLines
454 | titleLabel.font = UIFont(name: UIView.hr_toastFontName(), size: config.HRToastFontSize)
455 | titleLabel.textAlignment = .center
456 | titleLabel.lineBreakMode = .byWordWrapping
457 | titleLabel.textColor = UIView.hr_toastFontColor()
458 | titleLabel.backgroundColor = UIColor.clear
459 | titleLabel.alpha = 1.0
460 | titleLabel.text = title
461 |
462 | titleLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 751), for: .vertical)
463 | stackView.addArrangedSubview(titleLabel)
464 | }
465 |
466 | if let msg = msg {
467 | let msgLabel = UILabel()
468 | msgLabel.translatesAutoresizingMaskIntoConstraints = false
469 | msgLabel.numberOfLines = config.HRToastMaxMessageLines
470 | msgLabel.font = UIFont(name: UIView.hr_toastFontName(), size: config.HRToastFontSize)
471 | msgLabel.lineBreakMode = .byWordWrapping
472 | msgLabel.textAlignment = .center
473 | msgLabel.textColor = UIView.hr_toastFontColor()
474 | msgLabel.backgroundColor = UIColor.clear
475 | msgLabel.alpha = 1.0
476 | msgLabel.text = msg
477 |
478 | msgLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 751), for: .vertical)
479 | stackView.addArrangedSubview(msgLabel)
480 | }
481 | }
482 |
483 | }
484 |
--------------------------------------------------------------------------------