├── .gitignore
├── .swift-version
├── DEMO.gif
├── LICENSE
├── README.md
├── XHToastSwift.podspec
├── XHToastSwift
└── XHToast.swift
├── XHToastSwiftExample.xcodeproj
├── project.pbxproj
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcuserdata
│ │ └── xiaohui.xcuserdatad
│ │ └── UserInterfaceState.xcuserstate
└── xcuserdata
│ └── xiaohui.xcuserdatad
│ ├── xcdebugger
│ └── Breakpoints_v2.xcbkptlist
│ └── xcschemes
│ ├── XHToastSwiftExample.xcscheme
│ └── xcschememanagement.plist
└── XHToastSwiftExample
├── AppDelegate.swift
├── Assets.xcassets
└── AppIcon.appiconset
│ └── Contents.json
├── Base.lproj
└── LaunchScreen.storyboard
├── Info.plist
├── ViewController.swift
└── ViewController.xib
/.gitignore:
--------------------------------------------------------------------------------
1 | # Mac OS X
2 | .DS_Store
3 |
4 | # Xcode
5 |
6 | ## Build generated
7 | build/
8 | DerivedData
9 |
10 | ## Various settings
11 | *.pbxuser
12 | !default.pbxuser
13 | *.mode1v3
14 | !default.mode1v3
15 | *.mode2v3
16 | !default.mode2v3
17 | *.perspectivev3
18 | !default.perspectivev3
19 | xcuserdata
20 |
21 | ## Other
22 | *.xccheckout
23 | *.moved-aside
24 | *.xcuserstate
25 | *.xcscmblueprint
26 |
27 | ## Obj-C/Swift specific
28 | *.hmap
29 | *.ipa
30 |
31 | ## Playgrounds
32 | timeline.xctimeline
33 | playground.xcworkspace
34 |
35 | # Swift Package Manager
36 | .build/
37 |
38 | # Carthage
39 | Carthage/Build
40 |
--------------------------------------------------------------------------------
/.swift-version:
--------------------------------------------------------------------------------
1 | 3.0
2 |
--------------------------------------------------------------------------------
/DEMO.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderZhuXH/XHToastSwift/c379faca1ae472be5af9076705c0ea099a223ac3/DEMO.gif
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015-2016 XHToastSwift (https://github.com/CoderZhuXH/XHToastSwift)
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
13 | all 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
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # XHToastSwift
2 | #### 简洁轻便提示工具,一行代码,既可完成提示信息显示.
3 |
4 | [](https://github.com/CoderZhuXH/XHToastSwift)
5 | [](https://github.com/CoderZhuXH/XHToastSwift)
6 | [](http://cocoadocs.org/docsets/XHToastSwift)
7 | 
8 | [](http://cocoadocs.org/docsets/XHToastSwift)
9 | [](https://github.com/CoderZhuXH/XHToastSwift/blob/master/LICENSE)
10 |
11 | ==============
12 |
13 | #### OC版本请戳这里>>> https://github.com/CoderZhuXH/XHToast
14 | ### 技术交流群(群号:537476189)
15 |
16 | ## 效果
17 | 
18 |
19 | ## 使用方法
20 | #### 1.普通调用
21 | ```swift
22 | /*
23 | 您只需要调用一行代码,既可完成提示信息显示
24 | */
25 |
26 | //1.在window上显示toast
27 |
28 | /*
29 | 中间显示
30 | */
31 | XHToast.showCenterWithText("您要显示的提示信息")
32 |
33 | /*
34 | 上方显示
35 | */
36 | XHToast.showTopWithText("您要显示的提示信息")
37 |
38 | /*
39 | 下方显示
40 | */
41 | XHToast.showBottomWithText("您要显示的提示信息")
42 |
43 |
44 | //2.你也可以这样调用,在view上显示toast
45 | /*
46 | 中间显示
47 | */
48 | self.view.showXHToastCenterWithText("您要显示的提示信息")
49 |
50 | /*
51 | 上方显示
52 | */
53 | self.view.showXHToastTopWithText("您要显示的提示信息")
54 |
55 | /**
56 | * 底端显示
57 | */
58 | self.view.showXHToastBottomWithText("您要显示的提示信息")
59 |
60 | ```
61 | #### 2.自定义Toast停留时间+到屏幕上端/下端距离(见如下方法)
62 | ##### 1.显示至window
63 | ```swift
64 |
65 | // MARK:-中间显示
66 |
67 | /**
68 | 中间显示+自定义时间
69 |
70 | - parameter text: 文字
71 | - parameter duration: 自定义停留时间
72 | */
73 | public class func showCenterWithText(_ text:String, duration:CGFloat)
74 |
75 | // MARK:-上方显示
76 |
77 | /**
78 | 上方显示+自定义停留时间
79 |
80 | - parameter text: 文字
81 | - parameter duration: 自定义停留时间
82 | */
83 | public class func showTopWithText(_ text:String, duration:CGFloat)
84 |
85 | /**
86 | 上方显示+自定义到顶部距离
87 |
88 | - parameter text: 文字
89 | - parameter topOffset: 自定义到顶部距离
90 | */
91 | public class func showTopWithText(_ text:String,topOffset:CGFloat)
92 |
93 | /**
94 | 上方显示+自定义到顶部距离+自定义停留时间
95 |
96 | - parameter text: 文字
97 | - parameter topOffset: 自定义到顶部距离
98 | - parameter duration: 自定义停留时间
99 | */
100 | public class func showTopWithText(_ text:String, topOffset:CGFloat,duration:CGFloat)
101 |
102 | // MARK:-下方显示
103 |
104 | /**
105 | 下方显示+自定义停留时间
106 |
107 | - parameter text: 文字
108 | - parameter duration: 自定义停留时间
109 | */
110 | public class func showBottomWithText(_ text:String,duration:CGFloat)
111 |
112 | /**
113 | 下方显示+自定义到底部距离
114 |
115 | - parameter text: 文字
116 | - parameter bottomOffset: 自定义到底部距离
117 | */
118 | public class func showBottomWithText(_ text:String,bottomOffset:CGFloat)
119 |
120 | /**
121 | 下方显示+自定义到底部距离+自定义停留时间
122 |
123 | - parameter text: 文字
124 | - parameter bottomOffset: 自定义到底部距离
125 | - parameter duration: 自定义停留时间
126 | */
127 | public class func showBottomWithText(_ text:String,bottomOffset:CGFloat,duration:CGFloat)
128 |
129 | ```
130 | ##### 2.显示至view
131 |
132 | ```swift
133 |
134 | // MARK:- 中间显示
135 |
136 |
137 | /// 中间显示+自定义停留时间
138 | ///
139 | /// - Parameters:
140 | /// - text: 文字
141 | /// - duration: 自定义停留时间
142 | public func showXHToastCenterWithText(_ text:String , duration:CGFloat)
143 |
144 |
145 | /// 上方显示+自定义停留时间
146 | ///
147 | /// - Parameters:
148 | /// - text: 文字
149 | /// - duration: 自定义停留时间
150 | public func showXHToastTopWithText(_ text:String, duration:CGFloat)
151 |
152 |
153 | // MARK:- 上方显示
154 |
155 | /// 上方显示+自定义到顶部距离
156 | ///
157 | /// - Parameters:
158 | /// - text: 文字
159 | /// - topOffset: 自定义到顶部距离
160 | public func showXHToastTopWithText(_ text:String,topOffset:CGFloat)
161 |
162 |
163 | /// 上方显示+自定义到顶部距离+自定义停留时间
164 | ///
165 | /// - Parameters:
166 | /// - text: 文字
167 | /// - topOffset: 自定义到顶部距离
168 | /// - duration: 自定义停留时间
169 | public func showXHToastTopWithText(_ text:String,topOffset:CGFloat,duration:CGFloat)
170 |
171 |
172 | // MARK:- 下方显示
173 |
174 | /// 下方显示+自定义停留时间
175 | ///
176 | /// - Parameters:
177 | /// - text: 文字
178 | /// - duration: 自定义停留时间
179 | public func showXHToastBottomWithText(_ text:String, duration:CGFloat)
180 |
181 |
182 | /// 下方显示+自定义到顶部距离
183 | ///
184 | /// - Parameters:
185 | /// - text: 文字
186 | /// - topOffset: 自定义到顶部距离
187 | public func showXHToastBottomWithText(_ text:String,bottomOffset:CGFloat)
188 |
189 |
190 | /// 下方显示+自定义到顶部距离+自定义停留时间
191 | ///
192 | /// - Parameters:
193 | /// - text: 文字
194 | /// - topOffset: 自定义到顶部距离
195 | /// - duration: 自定义停留时间
196 | public func showXHToastBottomWithText(_ text:String,bottomOffset:CGFloat,duration:CGFloat)
197 |
198 |
199 | ```
200 | ## 安装
201 | ### 1.手动添加:
202 | * 1.将 XHToastSwift文件夹添加到工程目录中即可
203 |
204 | ### 2.CocoaPods:
205 | * 1.在 Podfile 中添加 pod 'XHToastSwift'
206 | * 2.执行 pod install 或 pod update
207 | * 3.导入 import XHToastSwift
208 |
209 | ### 3.Tips
210 | * 1.如果发现pod search XHToastSwift 搜索出来的不是最新版本,需要在终端执行cd desktop退回到desktop,然后执行pod setup命令更新本地spec缓存(需要几分钟),然后再搜索就可以了
211 | * 2.如果你发现你执行pod install后,导入的不是最新版本,请删除Podfile.lock文件,在执行一次 pod install
212 |
213 | ## 系统要求
214 | * 该项目最低支持 iOS 8.0 和 Xcode 8
215 |
216 | ## 许可证
217 | XHToast 使用 MIT 许可证,详情见 LICENSE 文件
--------------------------------------------------------------------------------
/XHToastSwift.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |s|
2 | s.name = "XHToastSwift"
3 | s.version = "1.2.0"
4 | s.summary = "简洁轻便提示工具,一行代码既可完成提示信息显示,支持自定义显示位置及停留时间."
5 | s.homepage = "https://github.com/CoderZhuXH/XHToastSwift"
6 | s.license = { :type => "MIT", :file => "LICENSE" }
7 | s.authors = { "Zhu Xiaohui" => "977950862@qq.com"}
8 | s.platform = :ios, "8.0"
9 | s.source = { :git => "https://github.com/CoderZhuXH/XHToastSwift.git", :tag => s.version }
10 | s.source_files = "XHToastSwift", "*.{swift}"
11 | s.requires_arc = true
12 | s.framework = "UIKit"
13 | #s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3.0' }
14 |
15 | end
16 |
--------------------------------------------------------------------------------
/XHToastSwift/XHToast.swift:
--------------------------------------------------------------------------------
1 | //
2 | // XHToast.swift
3 | // XHToastSwiftExample
4 | //
5 | // Created by xiaohui on 16/8/12.
6 | // Copyright © 2016年 CoderZhuXH. All rights reserved.
7 | // 代码地址:https://github.com/CoderZhuXH/XHToastSwift
8 |
9 |
10 | import UIKit
11 |
12 | /**
13 | * Toast默认停留时间
14 | */
15 | private let ToastDispalyDuration:CGFloat = 1.2
16 | /**
17 | * Toast到顶端/底端默认距离
18 | */
19 | private let ToastSpace:CGFloat = 100.0
20 | /**
21 | * Toast背景颜色
22 | */
23 | private let ToastBackgroundColor = UIColor(red:0.2,green:0.2,blue:0.2,alpha:0.75)
24 |
25 | //在window上显示
26 | extension XHToast
27 | {
28 | //MARK:-中间显示
29 |
30 | /**
31 | 中间显示
32 |
33 | - parameter text: 文字
34 | */
35 | public class func showCenterWithText(_ text: String) {
36 |
37 | XHToast.showCenterWithText(text, duration:ToastDispalyDuration)
38 | }
39 |
40 | /**
41 | 中间显示+自定义时间
42 |
43 | - parameter text: 文字
44 | - parameter duration: 自定义停留时间
45 | */
46 | public class func showCenterWithText(_ text:String,duration:CGFloat) {
47 | let toast = XHToast(text: text)
48 | toast.duration = duration
49 | toast.showIn(UIWindow.window())
50 | }
51 |
52 | // MARK:-上方显示
53 |
54 | /**
55 | 上方显示
56 |
57 | - parameter text: 文字
58 | */
59 | public class func showTopWithText(_ text:String) {
60 | XHToast.showTopWithText(text, topOffset:ToastSpace, duration:ToastDispalyDuration)
61 | }
62 |
63 | /**
64 | 上方显示+自定义停留时间
65 |
66 | - parameter text: 文字
67 | - parameter duration: 自定义停留时间
68 | */
69 | public class func showTopWithText(_ text:String, duration:CGFloat) {
70 | XHToast.showTopWithText(text, topOffset:ToastSpace, duration:duration)
71 | }
72 |
73 | /**
74 | 上方显示+自定义到顶部距离
75 |
76 | - parameter text: 文字
77 | - parameter topOffset: 自定义到顶部距离
78 | */
79 | public class func showTopWithText(_ text:String,topOffset:CGFloat) {
80 | XHToast.showTopWithText(text, topOffset:topOffset, duration:ToastDispalyDuration)
81 | }
82 |
83 | /**
84 | 上方显示+自定义到顶部距离+自定义停留时间
85 |
86 | - parameter text: 文字
87 | - parameter topOffset: 自定义到顶部距离
88 | - parameter duration: 自定义停留时间
89 | */
90 | public class func showTopWithText(_ text:String, topOffset:CGFloat,duration:CGFloat) {
91 | let toast = XHToast(text: text)
92 | toast.duration = duration
93 | toast.showIn(UIWindow.window(), topOffset: topOffset)
94 | }
95 |
96 | // MARK:-下方显示
97 |
98 | /**
99 | 下方显示
100 |
101 | - parameter text: 文字
102 | */
103 | public class func showBottomWithText(_ text:String) {
104 | XHToast.showBottomWithText(text, bottomOffset:ToastSpace, duration:ToastDispalyDuration)
105 | }
106 |
107 | /**
108 | 下方显示+自定义停留时间
109 |
110 | - parameter text: 文字
111 | - parameter duration: 自定义停留时间
112 | */
113 | public class func showBottomWithText(_ text:String,duration:CGFloat) {
114 | XHToast.showBottomWithText(text, bottomOffset:ToastSpace, duration:duration)
115 | }
116 |
117 | /**
118 | 下方显示+自定义到底部距离
119 |
120 | - parameter text: 文字
121 | - parameter bottomOffset: 自定义到底部距离
122 | */
123 | public class func showBottomWithText(_ text:String,bottomOffset:CGFloat) {
124 | XHToast.showBottomWithText(text, bottomOffset:bottomOffset, duration:ToastDispalyDuration)
125 | }
126 |
127 | /**
128 | 下方显示+自定义到底部距离+自定义停留时间
129 |
130 | - parameter text: 文字
131 | - parameter bottomOffset: 自定义到底部距离
132 | - parameter duration: 自定义停留时间
133 | */
134 | public class func showBottomWithText(_ text:String,bottomOffset:CGFloat,duration:CGFloat) {
135 | let toast: XHToast = XHToast(text: text)
136 | toast.duration = duration
137 | toast.showIn(UIWindow.window(), bottomOffset: bottomOffset)
138 | }
139 |
140 | }
141 |
142 | //在view上显示
143 | extension UIView
144 | {
145 | // MARK:- 中间显示
146 |
147 | /// 中间显示
148 | ///
149 | /// - Parameter text: 文字
150 | public func showXHToastCenterWithText(_ text:String){
151 |
152 | self.showXHToastCenterWithText(text, duration: ToastDispalyDuration)
153 |
154 | }
155 |
156 |
157 | /// 中间显示+自定义停留时间
158 | ///
159 | /// - Parameters:
160 | /// - text: 文字
161 | /// - duration: 自定义停留时间
162 | public func showXHToastCenterWithText(_ text:String , duration:CGFloat){
163 |
164 | let toast: XHToast = XHToast(text: text)
165 | toast.duration = duration
166 | toast.showIn(self)
167 |
168 | }
169 |
170 |
171 | // MARK:-上方显示
172 |
173 | /// 上方显示
174 | ///
175 | /// - Parameter text: 文字
176 | public func showXHToastTopWithText(_ text:String){
177 |
178 | self.showXHToastTopWithText(text, topOffset: ToastSpace, duration: ToastDispalyDuration)
179 | }
180 |
181 |
182 | /// 上方显示+自定义停留时间
183 | ///
184 | /// - Parameters:
185 | /// - text: 文字
186 | /// - duration: 自定义停留时间
187 | public func showXHToastTopWithText(_ text:String, duration:CGFloat){
188 |
189 | self.showXHToastTopWithText(text, topOffset: ToastSpace, duration: duration)
190 |
191 | }
192 |
193 |
194 | /// 上方显示+自定义到顶部距离
195 | ///
196 | /// - Parameters:
197 | /// - text: 文字
198 | /// - topOffset: 自定义到顶部距离
199 | public func showXHToastTopWithText(_ text:String,topOffset:CGFloat){
200 |
201 | self.showXHToastTopWithText(text, topOffset: topOffset, duration: ToastDispalyDuration)
202 |
203 | }
204 |
205 |
206 | /// 上方显示+自定义到顶部距离+自定义停留时间
207 | ///
208 | /// - Parameters:
209 | /// - text: 文字
210 | /// - topOffset: 自定义到顶部距离
211 | /// - duration: 自定义停留时间
212 | public func showXHToastTopWithText(_ text:String,topOffset:CGFloat,duration:CGFloat) {
213 |
214 | let toast: XHToast = XHToast(text: text)
215 | toast.duration = duration
216 | toast.showIn(self, topOffset: topOffset)
217 |
218 | }
219 |
220 |
221 | //MARK:-下方显示
222 |
223 | /// 下方显示
224 | ///
225 | /// - Parameter text: 文字
226 | public func showXHToastBottomWithText(_ text:String){
227 | self.showXHToastBottomWithText(text, bottomOffset: ToastSpace, duration: ToastDispalyDuration)
228 | }
229 |
230 |
231 | /// 下方显示+自定义停留时间
232 | ///
233 | /// - Parameters:
234 | /// - text: 文字
235 | /// - duration: 自定义停留时间
236 | public func showXHToastBottomWithText(_ text:String, duration:CGFloat){
237 |
238 | self.showXHToastBottomWithText(text, bottomOffset: ToastSpace, duration: duration)
239 |
240 | }
241 |
242 |
243 | /// 下方显示+自定义到顶部距离
244 | ///
245 | /// - Parameters:
246 | /// - text: 文字
247 | /// - topOffset: 自定义到顶部距离
248 | public func showXHToastBottomWithText(_ text:String,bottomOffset:CGFloat){
249 |
250 | self.showXHToastBottomWithText(text, bottomOffset: bottomOffset, duration: ToastDispalyDuration)
251 |
252 | }
253 |
254 | /// 下方显示+自定义到顶部距离+自定义停留时间
255 | ///
256 | /// - Parameters:
257 | /// - text: 文字
258 | /// - topOffset: 自定义到顶部距离
259 | /// - duration: 自定义停留时间
260 | public func showXHToastBottomWithText(_ text:String,bottomOffset:CGFloat,duration:CGFloat) {
261 |
262 | let toast: XHToast = XHToast(text: text)
263 | toast.duration = duration
264 | toast.showIn(self, bottomOffset: bottomOffset)
265 | }
266 |
267 | }
268 |
269 | extension UIWindow
270 | {
271 | fileprivate class func window() -> UIWindow{
272 | let window = UIApplication.shared.windows.last!
273 | if(!window.isHidden){
274 | return window;
275 | }
276 | return (UIApplication.shared.delegate?.window!)!;
277 | }
278 | }
279 |
280 | open class XHToast:NSObject {
281 |
282 | var contentView: UIButton
283 | var duration:CGFloat
284 |
285 | init(text: String) {
286 |
287 | duration = ToastDispalyDuration
288 |
289 | let font = UIFont.boldSystemFont(ofSize: 16)
290 | let attributes = [NSFontAttributeName: font]
291 | let rect = text.boundingRect(with: CGSize(width: 250,height: CGFloat.greatestFiniteMagnitude), options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes:attributes, context: nil)
292 | let textLabel: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: rect.size.width+40, height: rect.size.height+20))
293 | textLabel.backgroundColor = UIColor.clear
294 | textLabel.textColor = UIColor.white
295 | textLabel.textAlignment = NSTextAlignment.center
296 | textLabel.font = font
297 | textLabel.text = text
298 | textLabel.numberOfLines = 0
299 | contentView = UIButton(frame: CGRect(x: 0, y: 0, width: textLabel.frame.size.width, height: textLabel.frame.size.height))
300 | contentView.layer.cornerRadius = 20.0
301 | contentView.backgroundColor = ToastBackgroundColor
302 | contentView.addSubview(textLabel)
303 | contentView.autoresizingMask = UIViewAutoresizing.flexibleWidth
304 |
305 | super.init()
306 |
307 | contentView.addTarget(self, action:#selector(toastTaped(_:)), for: UIControlEvents.touchDown)
308 | contentView.alpha = 0.0
309 |
310 | }
311 |
312 | required public init?(coder aDecoder: NSCoder) {
313 | fatalError("init(coder:) has not been implemented")
314 | }
315 |
316 | fileprivate func dismissToast() {
317 | contentView.removeFromSuperview()
318 | }
319 |
320 | @objc fileprivate func toastTaped(_ sender: UIButton) {
321 |
322 | self.hideAnimation()
323 | }
324 |
325 | fileprivate func showAnimation() {
326 |
327 | UIView.animate(withDuration: 0.3, delay: 0, options: UIViewAnimationOptions.curveEaseIn, animations: {
328 |
329 | self.contentView.alpha = 1.0
330 |
331 | }) { (completion) in
332 |
333 |
334 | }
335 | }
336 |
337 | fileprivate func hideAnimation() {
338 |
339 | UIView.animate(withDuration: 0.3, delay: 0, options: UIViewAnimationOptions.curveEaseOut, animations: {
340 |
341 | self.contentView.alpha = 0.0
342 |
343 | }) { (completion) in
344 |
345 |
346 | }
347 |
348 | }
349 |
350 | fileprivate func showIn(_ view:UIView) {
351 |
352 | contentView.center = view.center
353 | view.addSubview(contentView)
354 | self.showAnimation()
355 | DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(UInt64(duration) * NSEC_PER_SEC)) / Double(NSEC_PER_SEC)) {
356 |
357 | self.hideAnimation()
358 |
359 | }
360 | }
361 |
362 | fileprivate func showIn(_ view:UIView,topOffset top: CGFloat) {
363 |
364 | contentView.center = CGPoint(x: view.center.x, y: top+contentView.frame.size.height/2)
365 | view.addSubview(contentView)
366 | self.showAnimation()
367 | DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(UInt64(duration) * NSEC_PER_SEC)) / Double(NSEC_PER_SEC)) {
368 |
369 | self.hideAnimation()
370 | }
371 | }
372 |
373 | fileprivate func showIn(_ view:UIView,bottomOffset bottom: CGFloat) {
374 |
375 | contentView.center = CGPoint(x: view.center.x, y: view.frame.size.height-(bottom+contentView.frame.size.height/2))
376 | view.addSubview(contentView)
377 | self.showAnimation()
378 | DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(UInt64(duration) * NSEC_PER_SEC)) / Double(NSEC_PER_SEC)) {
379 |
380 | self.hideAnimation()
381 | }
382 | }
383 |
384 | }
385 |
386 |
--------------------------------------------------------------------------------
/XHToastSwiftExample.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 4B3F2F461D5E1FD000F4FB85 /* ViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B3F2F451D5E1FD000F4FB85 /* ViewController.xib */; };
11 | 4B7543441D5DE5C5007D3C7E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B7543431D5DE5C5007D3C7E /* AppDelegate.swift */; };
12 | 4B7543461D5DE5C5007D3C7E /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B7543451D5DE5C5007D3C7E /* ViewController.swift */; };
13 | 4B75434B1D5DE5C5007D3C7E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4B75434A1D5DE5C5007D3C7E /* Assets.xcassets */; };
14 | 4B75434E1D5DE5C5007D3C7E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4B75434C1D5DE5C5007D3C7E /* LaunchScreen.storyboard */; };
15 | 4B7C87AD1D61A23D0099E1FA /* XHToast.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B7C87AC1D61A23D0099E1FA /* XHToast.swift */; };
16 | /* End PBXBuildFile section */
17 |
18 | /* Begin PBXFileReference section */
19 | 4B3F2F451D5E1FD000F4FB85 /* ViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ViewController.xib; sourceTree = ""; };
20 | 4B7543401D5DE5C5007D3C7E /* XHToastSwiftExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = XHToastSwiftExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
21 | 4B7543431D5DE5C5007D3C7E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; };
22 | 4B7543451D5DE5C5007D3C7E /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; };
23 | 4B75434A1D5DE5C5007D3C7E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
24 | 4B75434D1D5DE5C5007D3C7E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
25 | 4B75434F1D5DE5C5007D3C7E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
26 | 4B7C87AC1D61A23D0099E1FA /* XHToast.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XHToast.swift; sourceTree = ""; };
27 | /* End PBXFileReference section */
28 |
29 | /* Begin PBXFrameworksBuildPhase section */
30 | 4B75433D1D5DE5C5007D3C7E /* Frameworks */ = {
31 | isa = PBXFrameworksBuildPhase;
32 | buildActionMask = 2147483647;
33 | files = (
34 | );
35 | runOnlyForDeploymentPostprocessing = 0;
36 | };
37 | /* End PBXFrameworksBuildPhase section */
38 |
39 | /* Begin PBXGroup section */
40 | 4B7543371D5DE5C5007D3C7E = {
41 | isa = PBXGroup;
42 | children = (
43 | 4B7543421D5DE5C5007D3C7E /* XHToastSwiftExample */,
44 | 4B7C87AB1D61A23D0099E1FA /* XHToastSwift */,
45 | 4B7543411D5DE5C5007D3C7E /* Products */,
46 | );
47 | sourceTree = "";
48 | };
49 | 4B7543411D5DE5C5007D3C7E /* Products */ = {
50 | isa = PBXGroup;
51 | children = (
52 | 4B7543401D5DE5C5007D3C7E /* XHToastSwiftExample.app */,
53 | );
54 | name = Products;
55 | sourceTree = "";
56 | };
57 | 4B7543421D5DE5C5007D3C7E /* XHToastSwiftExample */ = {
58 | isa = PBXGroup;
59 | children = (
60 | 4B7543431D5DE5C5007D3C7E /* AppDelegate.swift */,
61 | 4B7543451D5DE5C5007D3C7E /* ViewController.swift */,
62 | 4B3F2F451D5E1FD000F4FB85 /* ViewController.xib */,
63 | 4B75434A1D5DE5C5007D3C7E /* Assets.xcassets */,
64 | 4B75434C1D5DE5C5007D3C7E /* LaunchScreen.storyboard */,
65 | 4B75434F1D5DE5C5007D3C7E /* Info.plist */,
66 | );
67 | path = XHToastSwiftExample;
68 | sourceTree = "";
69 | };
70 | 4B7C87AB1D61A23D0099E1FA /* XHToastSwift */ = {
71 | isa = PBXGroup;
72 | children = (
73 | 4B7C87AC1D61A23D0099E1FA /* XHToast.swift */,
74 | );
75 | path = XHToastSwift;
76 | sourceTree = "";
77 | };
78 | /* End PBXGroup section */
79 |
80 | /* Begin PBXNativeTarget section */
81 | 4B75433F1D5DE5C5007D3C7E /* XHToastSwiftExample */ = {
82 | isa = PBXNativeTarget;
83 | buildConfigurationList = 4B7543521D5DE5C5007D3C7E /* Build configuration list for PBXNativeTarget "XHToastSwiftExample" */;
84 | buildPhases = (
85 | 4B75433C1D5DE5C5007D3C7E /* Sources */,
86 | 4B75433D1D5DE5C5007D3C7E /* Frameworks */,
87 | 4B75433E1D5DE5C5007D3C7E /* Resources */,
88 | );
89 | buildRules = (
90 | );
91 | dependencies = (
92 | );
93 | name = XHToastSwiftExample;
94 | productName = XHToastSwiftExample;
95 | productReference = 4B7543401D5DE5C5007D3C7E /* XHToastSwiftExample.app */;
96 | productType = "com.apple.product-type.application";
97 | };
98 | /* End PBXNativeTarget section */
99 |
100 | /* Begin PBXProject section */
101 | 4B7543381D5DE5C5007D3C7E /* Project object */ = {
102 | isa = PBXProject;
103 | attributes = {
104 | LastSwiftUpdateCheck = 0730;
105 | LastUpgradeCheck = 0800;
106 | ORGANIZATIONNAME = qiantou;
107 | TargetAttributes = {
108 | 4B75433F1D5DE5C5007D3C7E = {
109 | CreatedOnToolsVersion = 7.3.1;
110 | DevelopmentTeam = 6UD925M2H4;
111 | LastSwiftMigration = 0800;
112 | ProvisioningStyle = Automatic;
113 | };
114 | };
115 | };
116 | buildConfigurationList = 4B75433B1D5DE5C5007D3C7E /* Build configuration list for PBXProject "XHToastSwiftExample" */;
117 | compatibilityVersion = "Xcode 3.2";
118 | developmentRegion = English;
119 | hasScannedForEncodings = 0;
120 | knownRegions = (
121 | en,
122 | Base,
123 | );
124 | mainGroup = 4B7543371D5DE5C5007D3C7E;
125 | productRefGroup = 4B7543411D5DE5C5007D3C7E /* Products */;
126 | projectDirPath = "";
127 | projectRoot = "";
128 | targets = (
129 | 4B75433F1D5DE5C5007D3C7E /* XHToastSwiftExample */,
130 | );
131 | };
132 | /* End PBXProject section */
133 |
134 | /* Begin PBXResourcesBuildPhase section */
135 | 4B75433E1D5DE5C5007D3C7E /* Resources */ = {
136 | isa = PBXResourcesBuildPhase;
137 | buildActionMask = 2147483647;
138 | files = (
139 | 4B75434E1D5DE5C5007D3C7E /* LaunchScreen.storyboard in Resources */,
140 | 4B3F2F461D5E1FD000F4FB85 /* ViewController.xib in Resources */,
141 | 4B75434B1D5DE5C5007D3C7E /* Assets.xcassets in Resources */,
142 | );
143 | runOnlyForDeploymentPostprocessing = 0;
144 | };
145 | /* End PBXResourcesBuildPhase section */
146 |
147 | /* Begin PBXSourcesBuildPhase section */
148 | 4B75433C1D5DE5C5007D3C7E /* Sources */ = {
149 | isa = PBXSourcesBuildPhase;
150 | buildActionMask = 2147483647;
151 | files = (
152 | 4B7543461D5DE5C5007D3C7E /* ViewController.swift in Sources */,
153 | 4B7C87AD1D61A23D0099E1FA /* XHToast.swift in Sources */,
154 | 4B7543441D5DE5C5007D3C7E /* AppDelegate.swift in Sources */,
155 | );
156 | runOnlyForDeploymentPostprocessing = 0;
157 | };
158 | /* End PBXSourcesBuildPhase section */
159 |
160 | /* Begin PBXVariantGroup section */
161 | 4B75434C1D5DE5C5007D3C7E /* LaunchScreen.storyboard */ = {
162 | isa = PBXVariantGroup;
163 | children = (
164 | 4B75434D1D5DE5C5007D3C7E /* Base */,
165 | );
166 | name = LaunchScreen.storyboard;
167 | sourceTree = "";
168 | };
169 | /* End PBXVariantGroup section */
170 |
171 | /* Begin XCBuildConfiguration section */
172 | 4B7543501D5DE5C5007D3C7E /* Debug */ = {
173 | isa = XCBuildConfiguration;
174 | buildSettings = {
175 | ALWAYS_SEARCH_USER_PATHS = NO;
176 | CLANG_ANALYZER_NONNULL = YES;
177 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
178 | CLANG_CXX_LIBRARY = "libc++";
179 | CLANG_ENABLE_MODULES = YES;
180 | CLANG_ENABLE_OBJC_ARC = YES;
181 | CLANG_WARN_BOOL_CONVERSION = YES;
182 | CLANG_WARN_CONSTANT_CONVERSION = YES;
183 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
184 | CLANG_WARN_EMPTY_BODY = YES;
185 | CLANG_WARN_ENUM_CONVERSION = YES;
186 | CLANG_WARN_INFINITE_RECURSION = YES;
187 | CLANG_WARN_INT_CONVERSION = YES;
188 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
189 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
190 | CLANG_WARN_UNREACHABLE_CODE = YES;
191 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
192 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
193 | COPY_PHASE_STRIP = NO;
194 | DEBUG_INFORMATION_FORMAT = dwarf;
195 | ENABLE_STRICT_OBJC_MSGSEND = YES;
196 | ENABLE_TESTABILITY = YES;
197 | GCC_C_LANGUAGE_STANDARD = gnu99;
198 | GCC_DYNAMIC_NO_PIC = NO;
199 | GCC_NO_COMMON_BLOCKS = YES;
200 | GCC_OPTIMIZATION_LEVEL = 0;
201 | GCC_PREPROCESSOR_DEFINITIONS = (
202 | "DEBUG=1",
203 | "$(inherited)",
204 | );
205 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
206 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
207 | GCC_WARN_UNDECLARED_SELECTOR = YES;
208 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
209 | GCC_WARN_UNUSED_FUNCTION = YES;
210 | GCC_WARN_UNUSED_VARIABLE = YES;
211 | IPHONEOS_DEPLOYMENT_TARGET = 9.0;
212 | MTL_ENABLE_DEBUG_INFO = YES;
213 | ONLY_ACTIVE_ARCH = YES;
214 | SDKROOT = iphoneos;
215 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
216 | };
217 | name = Debug;
218 | };
219 | 4B7543511D5DE5C5007D3C7E /* Release */ = {
220 | isa = XCBuildConfiguration;
221 | buildSettings = {
222 | ALWAYS_SEARCH_USER_PATHS = NO;
223 | CLANG_ANALYZER_NONNULL = YES;
224 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
225 | CLANG_CXX_LIBRARY = "libc++";
226 | CLANG_ENABLE_MODULES = YES;
227 | CLANG_ENABLE_OBJC_ARC = YES;
228 | CLANG_WARN_BOOL_CONVERSION = YES;
229 | CLANG_WARN_CONSTANT_CONVERSION = YES;
230 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
231 | CLANG_WARN_EMPTY_BODY = YES;
232 | CLANG_WARN_ENUM_CONVERSION = YES;
233 | CLANG_WARN_INFINITE_RECURSION = YES;
234 | CLANG_WARN_INT_CONVERSION = YES;
235 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
236 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
237 | CLANG_WARN_UNREACHABLE_CODE = YES;
238 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
239 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
240 | COPY_PHASE_STRIP = NO;
241 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
242 | ENABLE_NS_ASSERTIONS = NO;
243 | ENABLE_STRICT_OBJC_MSGSEND = YES;
244 | GCC_C_LANGUAGE_STANDARD = gnu99;
245 | GCC_NO_COMMON_BLOCKS = YES;
246 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
247 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
248 | GCC_WARN_UNDECLARED_SELECTOR = YES;
249 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
250 | GCC_WARN_UNUSED_FUNCTION = YES;
251 | GCC_WARN_UNUSED_VARIABLE = YES;
252 | IPHONEOS_DEPLOYMENT_TARGET = 9.0;
253 | MTL_ENABLE_DEBUG_INFO = NO;
254 | SDKROOT = iphoneos;
255 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
256 | VALIDATE_PRODUCT = YES;
257 | };
258 | name = Release;
259 | };
260 | 4B7543531D5DE5C5007D3C7E /* Debug */ = {
261 | isa = XCBuildConfiguration;
262 | buildSettings = {
263 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
264 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
265 | DEVELOPMENT_TEAM = 6UD925M2H4;
266 | INFOPLIST_FILE = XHToastSwiftExample/Info.plist;
267 | IPHONEOS_DEPLOYMENT_TARGET = 9.0;
268 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
269 | PRODUCT_BUNDLE_IDENTIFIER = CoderZhuXH.XHToastSwiftExample;
270 | PRODUCT_NAME = "$(TARGET_NAME)";
271 | PROVISIONING_PROFILE_SPECIFIER = "";
272 | SWIFT_VERSION = 3.0;
273 | };
274 | name = Debug;
275 | };
276 | 4B7543541D5DE5C5007D3C7E /* Release */ = {
277 | isa = XCBuildConfiguration;
278 | buildSettings = {
279 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
280 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
281 | DEVELOPMENT_TEAM = 6UD925M2H4;
282 | INFOPLIST_FILE = XHToastSwiftExample/Info.plist;
283 | IPHONEOS_DEPLOYMENT_TARGET = 9.0;
284 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
285 | PRODUCT_BUNDLE_IDENTIFIER = CoderZhuXH.XHToastSwiftExample;
286 | PRODUCT_NAME = "$(TARGET_NAME)";
287 | PROVISIONING_PROFILE_SPECIFIER = "";
288 | SWIFT_VERSION = 3.0;
289 | };
290 | name = Release;
291 | };
292 | /* End XCBuildConfiguration section */
293 |
294 | /* Begin XCConfigurationList section */
295 | 4B75433B1D5DE5C5007D3C7E /* Build configuration list for PBXProject "XHToastSwiftExample" */ = {
296 | isa = XCConfigurationList;
297 | buildConfigurations = (
298 | 4B7543501D5DE5C5007D3C7E /* Debug */,
299 | 4B7543511D5DE5C5007D3C7E /* Release */,
300 | );
301 | defaultConfigurationIsVisible = 0;
302 | defaultConfigurationName = Release;
303 | };
304 | 4B7543521D5DE5C5007D3C7E /* Build configuration list for PBXNativeTarget "XHToastSwiftExample" */ = {
305 | isa = XCConfigurationList;
306 | buildConfigurations = (
307 | 4B7543531D5DE5C5007D3C7E /* Debug */,
308 | 4B7543541D5DE5C5007D3C7E /* Release */,
309 | );
310 | defaultConfigurationIsVisible = 0;
311 | defaultConfigurationName = Release;
312 | };
313 | /* End XCConfigurationList section */
314 | };
315 | rootObject = 4B7543381D5DE5C5007D3C7E /* Project object */;
316 | }
317 |
--------------------------------------------------------------------------------
/XHToastSwiftExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/XHToastSwiftExample.xcodeproj/project.xcworkspace/xcuserdata/xiaohui.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderZhuXH/XHToastSwift/c379faca1ae472be5af9076705c0ea099a223ac3/XHToastSwiftExample.xcodeproj/project.xcworkspace/xcuserdata/xiaohui.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/XHToastSwiftExample.xcodeproj/xcuserdata/xiaohui.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/XHToastSwiftExample.xcodeproj/xcuserdata/xiaohui.xcuserdatad/xcschemes/XHToastSwiftExample.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
54 |
56 |
62 |
63 |
64 |
65 |
69 |
70 |
71 |
72 |
73 |
74 |
80 |
82 |
88 |
89 |
90 |
91 |
93 |
94 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/XHToastSwiftExample.xcodeproj/xcuserdata/xiaohui.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | XHToastSwiftExample.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 4B75433F1D5DE5C5007D3C7E
16 |
17 | primary
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/XHToastSwiftExample/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // XHToastSwiftExample
4 | //
5 | // Created by xiaohui on 16/8/12.
6 | // Copyright © 2016年 CoderZhuXH. All rights reserved.
7 | // 代码地址:https://github.com/CoderZhuXH/XHToastSwift
8 |
9 | import UIKit
10 |
11 | @UIApplicationMain
12 | class AppDelegate: UIResponder, UIApplicationDelegate {
13 |
14 | var window: UIWindow?
15 |
16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
17 | // Override point for customization after application launch.
18 |
19 | window = UIWindow(frame:UIScreen.main.bounds)
20 | window?.backgroundColor = UIColor.white
21 |
22 | window?.rootViewController = UINavigationController.init(rootViewController:ViewController())
23 |
24 | window?.makeKeyAndVisible()
25 | return true
26 | }
27 |
28 | func applicationWillResignActive(_ application: UIApplication) {
29 | // 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.
30 | // 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.
31 | }
32 |
33 | func applicationDidEnterBackground(_ application: UIApplication) {
34 | // 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.
35 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
36 | }
37 |
38 | func applicationWillEnterForeground(_ application: UIApplication) {
39 | // 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.
40 | }
41 |
42 | func applicationDidBecomeActive(_ application: UIApplication) {
43 | // 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.
44 | }
45 |
46 | func applicationWillTerminate(_ application: UIApplication) {
47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
48 | }
49 |
50 |
51 | }
52 |
53 |
--------------------------------------------------------------------------------
/XHToastSwiftExample/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 | "info" : {
35 | "version" : 1,
36 | "author" : "xcode"
37 | }
38 | }
--------------------------------------------------------------------------------
/XHToastSwiftExample/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/XHToastSwiftExample/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 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/XHToastSwiftExample/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // XHToastSwiftExample
4 | //
5 | // Created by xiaohui on 16/8/12.
6 | // Copyright © 2016年 CoderZhuXH. All rights reserved.
7 | // 代码地址:https://github.com/CoderZhuXH/XHToastSwift
8 |
9 | import UIKit
10 |
11 | class ViewController: UIViewController{
12 |
13 | @IBOutlet weak var myTableView: UITableView!
14 |
15 | let dataArray = [["中间显示","中间显示+自定义停留时间"],
16 | ["顶端显示","顶端显示+自定义停留时间","顶端显示+自定义距顶端距离","顶端显示+自定义距顶端距离+自定义停留时间"],
17 | ["底部显示","底部显示+自定义停留时间","底部显示+自定义距底部距离","底部显示+自定义距底部距离+自定义停留时间"]
18 | ]
19 |
20 | override func viewDidLoad() {
21 | super.viewDidLoad()
22 | self.navigationItem.title = "XHToastSwiftExample"
23 | }
24 | }
25 | //MARK: - tableView
26 | extension ViewController:UITableViewDelegate,UITableViewDataSource
27 | {
28 | func numberOfSections(in tableView: UITableView) -> Int {
29 |
30 | return dataArray.count
31 | }
32 |
33 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
34 |
35 | let array = dataArray[section]
36 | return array.count
37 |
38 | }
39 |
40 | func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
41 |
42 | return 44.0
43 | }
44 |
45 | func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
46 |
47 | return 10
48 | }
49 | func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
50 |
51 | return 0.01
52 | }
53 |
54 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
55 |
56 | let cellID = "cell"
57 | var cell = tableView.dequeueReusableCell(withIdentifier: cellID)
58 | if cell == nil
59 | {
60 | cell = UITableViewCell(style:.default ,reuseIdentifier: cellID)
61 | }
62 | cell?.textLabel?.text = dataArray[(indexPath as NSIndexPath).section][(indexPath as NSIndexPath).row]
63 | cell?.textLabel?.numberOfLines = 0
64 | return cell!
65 | }
66 |
67 | func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
68 |
69 | tableView.deselectRow(at: indexPath, animated: false)
70 |
71 | //在window上显示
72 | self.showInWindow(indexPath: indexPath)
73 |
74 | //在view上显示
75 | //self.showInView(indexPath: indexPath)
76 |
77 | }
78 |
79 |
80 | //在window上显示
81 | func showInWindow(indexPath: IndexPath) {
82 |
83 |
84 | let text = dataArray[(indexPath as NSIndexPath).section][(indexPath as NSIndexPath).row]
85 |
86 | //MARK: - 中间
87 | if (indexPath as NSIndexPath).section == 0
88 | {
89 | if (indexPath as NSIndexPath).row == 0
90 | {
91 | /**
92 | * 中间显示
93 | */
94 | XHToast.showCenterWithText(text)
95 |
96 | }
97 | else if (indexPath as NSIndexPath).row == 1
98 | {
99 | /**
100 | * 中间显示+自定义停留时间
101 | */
102 | XHToast.showCenterWithText(text, duration:3.0)
103 |
104 | }
105 | }
106 | //MARK: - 顶端
107 | else if (indexPath as NSIndexPath).section == 1
108 | {
109 | /**
110 | * 顶端显示
111 | */
112 | if (indexPath as NSIndexPath).row == 0
113 | {
114 | XHToast.showTopWithText(text)
115 |
116 | }
117 | else if (indexPath as NSIndexPath).row == 1
118 | {
119 | /**
120 | * 顶端显示 + 自定义停留时间
121 | */
122 | XHToast.showTopWithText(text, duration:3.0)
123 |
124 |
125 | }
126 | else if (indexPath as NSIndexPath).row == 2
127 | {
128 | /**
129 | * 顶端显示 + 自定义到顶端距离
130 | */
131 | XHToast.showTopWithText(text, topOffset:150)
132 |
133 | }
134 | else if (indexPath as NSIndexPath).row == 3
135 | {
136 | /**
137 | * 顶端显示+自定义到顶端距离+自定义停留时间
138 | */
139 | XHToast.showTopWithText(text, topOffset:150, duration:3.0)
140 |
141 | }
142 | }
143 | //MARK: - 底部
144 | else
145 | {
146 | /**
147 | * 底端显示
148 | */
149 | if (indexPath as NSIndexPath).row == 0
150 | {
151 | XHToast.showBottomWithText(text)
152 | }
153 | else if (indexPath as NSIndexPath).row == 1
154 | {
155 | /**
156 | * 底端显示 + 自定义停留时间
157 | */
158 | XHToast.showBottomWithText(text, duration:3.0)
159 |
160 | }
161 | else if (indexPath as NSIndexPath).row == 2
162 | {
163 | /**
164 | * 底端显示 + 自定义到顶端距离
165 | */
166 | XHToast.showBottomWithText(text, bottomOffset:150)
167 | }
168 | else if (indexPath as NSIndexPath).row == 3
169 | {
170 | /**
171 | * 底端显示+自定义到顶端距离+自定义停留时间
172 | */
173 | XHToast.showBottomWithText(text, bottomOffset:150, duration:3.0)
174 |
175 | }
176 | }
177 |
178 | }
179 |
180 | //在view上显示
181 | func showInView(indexPath: IndexPath) {
182 |
183 | let text = dataArray[(indexPath as NSIndexPath).section][(indexPath as NSIndexPath).row]
184 |
185 | //MARK: - 中间
186 | if (indexPath as NSIndexPath).section == 0
187 | {
188 | if (indexPath as NSIndexPath).row == 0
189 | {
190 | /**
191 | * 中间显示
192 | */
193 |
194 | self.view.showXHToastCenterWithText(text)
195 |
196 |
197 | }
198 | else if (indexPath as NSIndexPath).row == 1
199 | {
200 | /**
201 | * 中间显示+自定义停留时间
202 | */
203 | self.view.showXHToastCenterWithText(text, duration: 3.0)
204 |
205 | }
206 | }
207 | //MARK: - 顶端
208 | else if (indexPath as NSIndexPath).section == 1
209 | {
210 |
211 | if (indexPath as NSIndexPath).row == 0
212 | {
213 | /**
214 | * 顶端显示
215 | */
216 | self.view.showXHToastTopWithText(text)
217 | }
218 | else if (indexPath as NSIndexPath).row == 1
219 | {
220 | /**
221 | * 顶端显示 + 自定义停留时间
222 | */
223 | self.view.showXHToastTopWithText(text, duration: 3.0)
224 |
225 | }
226 | else if (indexPath as NSIndexPath).row == 2
227 | {
228 | /**
229 | * 顶端显示 + 自定义到顶端距离
230 | */
231 | self.view.showXHToastTopWithText(text, topOffset: 150)
232 | }
233 | else if (indexPath as NSIndexPath).row == 3
234 | {
235 | /**
236 | * 顶端显示+自定义到顶端距离+自定义停留时间
237 | */
238 | self.view.showXHToastTopWithText(text, topOffset: 150, duration: 3.0)
239 |
240 | }
241 | }
242 | //MARK: - 底部
243 | else
244 | {
245 | if (indexPath as NSIndexPath).row == 0
246 | {
247 | /**
248 | * 底端显示
249 | */
250 | self.view.showXHToastBottomWithText(text)
251 | }
252 | else if (indexPath as NSIndexPath).row == 1
253 | {
254 | /**
255 | * 底端显示 + 自定义停留时间
256 | */
257 | self.view.showXHToastBottomWithText(text, duration:3.0)
258 |
259 | }
260 | else if (indexPath as NSIndexPath).row == 2
261 | {
262 | /**
263 | * 底端显示 + 自定义到顶端距离
264 | */
265 | self.view.showXHToastBottomWithText(text, bottomOffset: 150)
266 | }
267 | else if (indexPath as NSIndexPath).row == 3
268 | {
269 | /**
270 | * 底端显示+自定义到顶端距离+自定义停留时间
271 | */
272 | self.view.showXHToastBottomWithText(text, bottomOffset: 150, duration: 3.0)
273 | }
274 | }
275 |
276 | }
277 | }
278 |
--------------------------------------------------------------------------------
/XHToastSwiftExample/ViewController.xib:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------