提交 4410129e authored 作者: 逄仁秀's avatar 逄仁秀

no message

上级 80203052
......@@ -7,7 +7,10 @@ PODS:
- Adjust/Core (4.33.2)
- HandyJSON (5.0.2)
- IQKeyboardManager (6.5.10)
- lottie-ios (3.2.3)
- MBProgressHUD (1.2.0)
- MCToast (0.1.0):
- lottie-ios
- SDCycleScrollView (1.82):
- SDWebImage (>= 5.0.0)
- SDWebImage (5.14.2):
......@@ -22,6 +25,7 @@ DEPENDENCIES:
- HandyJSON
- IQKeyboardManager
- MBProgressHUD
- MCToast
- SDCycleScrollView
- SDWebImage
- SnapKit
......@@ -31,7 +35,9 @@ SPEC REPOS:
- Adjust
- HandyJSON
- IQKeyboardManager
- lottie-ios
- MBProgressHUD
- MCToast
- SDCycleScrollView
- SDWebImage
- SnapKit
......@@ -58,11 +64,13 @@ SPEC CHECKSUMS:
Adjust: 554c87d1b6799efa8169d34166b2a12862bf002c
HandyJSON: 9e4e236f5d2dbefad5155a77417bbea438201c03
IQKeyboardManager: 45a1fa55c1a5b02c61ac0fd7fd5b62bb4ad20d97
lottie-ios: c058aeafa76daa4cf64d773554bccc8385d0150e
MBProgressHUD: 3ee5efcc380f6a79a7cc9b363dd669c5e1ae7406
MCToast: accd8b0d4653bcd6b3b1a9770802c2358614e6a5
SDCycleScrollView: a0d74c3384caa72bdfc81470bdbc8c14b3e1fbcf
SDWebImage: b9a731e1d6307f44ca703b3976d18c24ca561e84
SnapKit: fe8a619752f3f27075cc9a90244d75c6c3f27e2a
PODFILE CHECKSUM: c5983d16970d9d4e9e25d2617a99901bf1ffd9a2
PODFILE CHECKSUM: 2c02dcc29a9ee1c95e1075175ad5362ae5816532
COCOAPODS: 1.11.3
../../../MCToast/MCToast/Classes/MCToast.h
\ No newline at end of file
../../../Target Support Files/lottie-ios/lottie-ios-umbrella.h
\ No newline at end of file
../../../Target Support Files/lottie-ios/lottie-ios.modulemap
\ No newline at end of file
../../../Target Support Files/MCToast/MCToast-umbrella.h
\ No newline at end of file
../../../MCToast/MCToast/Classes/MCToast.h
\ No newline at end of file
../../../Target Support Files/MCToast/MCToast.modulemap
\ No newline at end of file
MIT License
Copyright (c) 2019 mancongiOS
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
差异被折叠。
//
// MCToast+Remove.swift
// MCToast
//
// Created by Mccc on 2020/6/24.
//
import Foundation
extension UIResponder {
/// 移除toast
/// - Parameter callback: 移除成功的回调
public func mc_remove(callback: MCToast.MCToastCallback? = nil) {
MCToast.clearAllToast(callback: callback)
}
}
extension MCToast {
/// 移除toast
/// - Parameter callback: 移除成功的回调
public static func mc_remove(callback: MCToast.MCToastCallback? = nil) {
MCToast.clearAllToast(callback: callback)
}
}
internal extension Selector {
static let hideNotice = #selector(MCToast.hideNotice(_:))
}
extension MCToast {
/// 隐藏
@objc static func hideNotice(_ sender: AnyObject) {
if let window = sender as? UIWindow {
if let v = window.subviews.first {
UIView.animate(withDuration: 0.2, animations: {
if v.tag == sn_topBar {
v.frame = CGRect(x: 0, y: -v.frame.height, width: v.frame.width, height: v.frame.height)
}
v.alpha = 0
}, completion: { b in
if let index = windows.firstIndex(where: { (item) -> Bool in
return item == window
}) {
windows.remove(at: index)
}
})
}
}
}
/// 清空
static func clearAllToast(callback: MCToastCallback? = nil) {
self.cancelPreviousPerformRequests(withTarget: self)
if let _ = timer {
timer.cancel()
timer = nil
timerTimes = 0
}
windows.removeAll(keepingCapacity: false)
callback?()
}
}
extension MCToast {
/// 自动隐藏
static func autoRemove(window: UIWindow, duration: CGFloat, callback: MCToastCallback?) {
let autoClear : Bool = duration > 0 ? true : false
if autoClear {
self.perform(.hideNotice, with: window, afterDelay: TimeInterval(duration))
let time = DispatchTime.now() + .milliseconds(Int(duration * 1000))
DispatchQueue.main.asyncAfter(deadline: time) {
callback?()
}
}
}
}
//
// MCToast+Status.swift
// MCToast
//
// Created by Mccc on 2020/6/24.
//
extension MCToast {
/// Toast类型
public enum MCToastType {
/// 成功
case success
/// 失败
case failure
/// 警告
case warning
}
}
extension UIResponder {
/// 成功类型的Toast
/// - Parameters:
/// - text: 文字内容
/// - duration: 展示时间(秒)
/// - respond: 交互类型
/// - callback: 隐藏的回调
public func mc_success(_ text:String,
duration: CGFloat = MCToastConfig.shared.duration,
respond: MCToast.MCToastRespond = MCToastConfig.shared.respond,
callback: MCToast.MCToastCallback? = nil) {
DispatchQueue.main.async {
MCToast.mc_success(text, duration: duration, respond: respond, callback: callback)
}
}
/// 失败类型的Toast
/// - Parameters:
/// - text: 文字内容
/// - duration: 展示时间(秒)
/// - respond: 交互类型
/// - callback: 隐藏的回调
public func mc_failure(_ text: String,
duration:CGFloat = MCToastConfig.shared.duration,
respond: MCToast.MCToastRespond = MCToastConfig.shared.respond,
callback: MCToast.MCToastCallback? = nil) {
DispatchQueue.main.async {
MCToast.mc_failure(text, duration: duration, respond: respond, callback: callback)
}
}
/// 警告类型的Toast
/// - Parameters:
/// - text: 文字内容
/// - duration: 展示时间(秒)
/// - respond: 交互类型
/// - callback: 隐藏的回调
public func mc_warning(_ text: String,
duration:CGFloat = MCToastConfig.shared.duration,
respond: MCToast.MCToastRespond = MCToastConfig.shared.respond,
callback: MCToast.MCToastCallback? = nil) {
DispatchQueue.main.async {
MCToast.mc_warning(text, duration: duration, respond: respond, callback: callback)
}
}
}
extension MCToast {
/// 成功类型的Toast
/// - Parameters:
/// - text: 文字内容
/// - duration: 展示时间(秒)
/// - respond: 交互类型
/// - callback: 隐藏的回调
public static func mc_success(_ text:String,
duration: CGFloat = MCToastConfig.shared.duration,
respond: MCToast.MCToastRespond = MCToastConfig.shared.respond,
callback: MCToast.MCToastCallback? = nil) {
DispatchQueue.main.async {
MCToast.showStatus(.success, text: text, iconImage: nil, duration: duration, respond: respond, callback: callback)
}
}
/// 失败类型的Toast
/// - Parameters:
/// - text: 文字内容
/// - duration: 展示时间(秒)
/// - respond: 交互类型
/// - callback: 隐藏的回调
public static func mc_failure(_ text: String,
duration:CGFloat = MCToastConfig.shared.duration,
respond: MCToast.MCToastRespond = MCToastConfig.shared.respond,
callback: MCToast.MCToastCallback? = nil) {
DispatchQueue.main.async {
MCToast.showStatus(.failure, text: text, iconImage: nil, duration: duration, respond: respond, callback: callback)
}
}
/// 警告类型的Toast
/// - Parameters:
/// - text: 文字内容
/// - duration: 展示时间(秒)
/// - respond: 交互类型
/// - callback: 隐藏的回调
public static func mc_warning(_ text: String,
duration: CGFloat = MCToastConfig.shared.duration,
respond: MCToast.MCToastRespond = MCToastConfig.shared.respond,
callback: MCToast.MCToastCallback? = nil) {
DispatchQueue.main.async {
MCToast.showStatus(.warning, text: text, iconImage: nil, duration: duration, respond: respond,callback: callback)
}
}
}
// MARK: - 展示各种状态Toast
extension MCToast {
@discardableResult
public static func showStatus(_ type: MCToast.MCToastType?,
text: String,
iconImage: UIImage?,
duration: CGFloat,
respond: MCToast.MCToastRespond,
callback: MCToast.MCToastCallback? = nil) -> (imageView: UIImageView, label: UILabel) {
clearAllToast()
let kToastSize = MCToastConfig.shared.background.size
var kToastImageSize = MCToastConfig.shared.icon.size
if (kToastImageSize.width > kToastSize.width) || (kToastImageSize.height > kToastSize.height) {
kToastImageSize = CGSize.init(width: 40, height: 40)
}
var showImage: UIImage?
if let tempType = type {
switch tempType {
case .success:
if let trueImage = MCToastConfig.shared.icon.successImage {
showImage = trueImage
} else {
showImage = Bundle.loadImage("toast_success", from: "ToastBundle", in: "MCToast")
}
case .failure:
if let trueImage = MCToastConfig.shared.icon.failureImage {
showImage = trueImage
} else {
showImage = Bundle.loadImage("toast_failure", from: "ToastBundle", in: "MCToast")
}
case .warning:
if let trueImage = MCToastConfig.shared.icon.warningImage {
showImage = trueImage
} else {
showImage = Bundle.loadImage("toast_warning", from: "ToastBundle", in: "MCToast")
}
}
}
if let _ = iconImage {
showImage = iconImage
}
let checkmarkView = UIImageView(image: showImage)
let checkmarkX = (kToastSize.width - kToastImageSize.width) / 2
let checkmarkY = ((kToastSize.height - kToastImageSize.height - 35) / 2)
checkmarkView.frame = CGRect.init(x: checkmarkX, y: checkmarkY, width: kToastImageSize.width, height: kToastImageSize.height)
let label = UILabel()
// label.backgroundColor = UIColor.orange
label.font = MCToastConfig.shared.text.font
label.textColor = UIColor.white
label.text = text
label.numberOfLines = 2
label.textAlignment = NSTextAlignment.center
let labelWidth = kToastSize.width - 20
let labelSize = label.sizeThatFits(CGSize(width: labelWidth, height: CGFloat.greatestFiniteMagnitude))
label.frame = CGRect(x: 10, y: checkmarkView.frame.maxY + 15, width: labelWidth, height: labelSize.height)
let frame = CGRect(x: 0, y: 0, width: kToastSize.width, height: kToastSize.height - 20 + labelSize.height)
let window = MCToast.createWindow(respond: respond, frame: frame)
let mainView = MCToast.createMainView(frame: frame)
window.addSubview(mainView)
mainView.center = CGPoint.init(x: window.frame.size.width/2, y: kScreenHeight/2 - window.frame.origin.y)
mainView.addSubview(checkmarkView)
mainView.addSubview(label)
window.addSubview(mainView)
windows.append(window)
MCToast.autoRemove(window: window, duration: duration, callback: callback)
return (checkmarkView, label)
}
}
//
// MCToast+noticeBar.swift
// MCToast
//
// Created by Mccc on 2020/6/24.
//
import Foundation
extension UIResponder {
/// 在状态栏栏显示一个toast
/// - Parameters:
/// - text: 显示的文字内容
/// - duration: 显示的时长(秒)
/// - font: 文字字体
/// - backgroundColor: 背景颜色
/// - callback: 隐藏的回调
public func mc_statusBar( _ text: String,
duration: CGFloat = MCToastConfig.shared.duration,
font: UIFont = MCToastConfig.shared.text.font,
backgroundColor: UIColor? = nil,
callback: MCToast.MCToastCallback? = nil) {
MCToast.mc_statusBar(text, duration: duration, font: font, backgroundColor: backgroundColor, callback: callback)
}
}
extension MCToast {
/// 在状态栏栏显示一个toast
/// - Parameters:
/// - text: 显示的文字内容
/// - duration: 显示的时长(秒)
/// - font: 文字字体
/// - backgroundColor: 背景颜色
/// - callback: 隐藏的回调
public static func mc_statusBar(
_ text: String,
duration: CGFloat = MCToastConfig.shared.duration,
font: UIFont = MCToastConfig.shared.text.font,
backgroundColor: UIColor? = nil,
callback: MCToast.MCToastCallback? = nil) {
DispatchQueue.main.async {
MCToast.noticeOnStatusBar(text, duration: duration, backgroundColor: backgroundColor, font: font, callback: callback)
}
}
}
// MARK: - 在状态栏上显示提示框
extension MCToast {
@discardableResult
internal static func noticeOnStatusBar(
_ text: String,
duration: CGFloat,
backgroundColor: UIColor?,
font: UIFont,
callback: MCToast.MCToastCallback? = nil) -> UIWindow {
clearAllToast()
var labelY: CGFloat = 0
let labelHeight: CGFloat = 20
let topSafeAreaHeight: CGFloat = safeAreaInsets().top
var frame = UIApplication.shared.statusBarFrame
if frame.size.height > 20 {
frame.size.height = topSafeAreaHeight + labelHeight
labelY = topSafeAreaHeight
} else {
labelY = 0
}
let window = UIWindow()
window.backgroundColor = UIColor.clear
let view = UIView()
if let color = backgroundColor {
view.backgroundColor = color
} else {
view.backgroundColor = UIColor(red: 0x6a/0x100, green: 0xb4/0x100, blue: 0x9f/0x100, alpha: 1)
}
let label = UILabel()
label.frame = CGRect.init(x: 0, y: labelY, width: frame.width, height: labelHeight)
label.textAlignment = NSTextAlignment.center
label.font = font
label.textColor = UIColor.white
label.text = text
view.addSubview(label)
window.frame = frame
view.frame = frame
window.windowLevel = UIWindow.Level.statusBar
window.isHidden = false
window.addSubview(view)
windows.append(window)
var origPoint = view.frame.origin
origPoint.y = -(view.frame.size.height)
let destPoint = view.frame.origin
view.tag = sn_topBar
view.frame = CGRect(origin: origPoint, size: view.frame.size)
UIView.animate(withDuration: 0.3, animations: {
view.frame = CGRect(origin: destPoint, size: view.frame.size)
}, completion: { b in
MCToast.autoRemove(window: window, duration: duration, callback: callback)
})
return window
}
}
//
// MCToast+Text.swift
// MCToast
//
// Created by Mccc on 2020/6/24.
//
extension UIResponder {
/// 展示文字toast
/// - Parameters:
/// - text: 文字内容
/// - offset: 距离屏幕Y轴中心的距离(正下,负上)
/// - duration: 显示的时间(秒)
/// - respond: 交互类型
/// - callback: 隐藏的回调
public func mc_text(_ text: String,
offset: CGFloat? = nil,
duration: CGFloat = MCToastConfig.shared.duration,
respond: MCToast.MCToastRespond = MCToastConfig.shared.respond,
callback: MCToast.MCToastCallback? = nil) {
MCToast.mc_text(text, offset: offset, duration: duration, respond: respond, callback: callback)
}
}
extension MCToast {
/// 展示文字toast
/// - Parameters:
/// - text: 文字内容
/// - offset: 距离屏幕Y轴中心的距离(正下,负上)
/// - duration: 显示的时间(秒)
/// - respond: 交互类型
/// - callback: 隐藏的回调
public static func mc_text(_ text: String,
offset: CGFloat? = nil,
duration: CGFloat = MCToastConfig.shared.duration,
respond: MCToast.MCToastRespond = MCToastConfig.shared.respond,
callback: MCToast.MCToastCallback? = nil) {
DispatchQueue.main.async {
MCToast.showText(text, offset: offset, duration: duration, respond: respond, callback: callback)
}
}
}
// MARK: - 显示纯文字
extension MCToast {
/// 展示文字toast
/// - Parameters:
/// - text: 文字内容
/// - offset: 距离屏幕Y轴中心的距离(正下,负上)
/// - duration: 显示的时间(秒)
/// - respond: 交互类型
/// - callback: 隐藏的回调
@discardableResult
internal static func showText(_ text: String,
offset: CGFloat? = nil,
duration: CGFloat,
respond: MCToast.MCToastRespond,
callback: MCToast.MCToastCallback? = nil) -> UIWindow {
clearAllToast()
let label = UILabel()
label.text = text
label.numberOfLines = 0
label.font = MCToastConfig.shared.text.font
label.textAlignment = .center
label.textColor = UIColor.white
let labelWidth = kScreenWidth-(MCToastConfig.shared.spacing.margin + MCToastConfig.shared.spacing.padding) * 2
let size = label.sizeThatFits(CGSize(width: labelWidth, height: CGFloat.greatestFiniteMagnitude))
label.frame = CGRect(x: 0, y: 0, width: size.width, height: size.height)
let superFrame = CGRect(x: 0, y: 0, width: label.frame.width + 2*MCToastConfig.shared.spacing.padding, height: label.frame.height + 30)
let mainView = MCToast.createMainView(frame: superFrame)
let window = MCToast.createWindow(respond: respond, frame: superFrame)
var tempOffset: CGFloat = 0
if let temp = offset {
tempOffset = temp
} else {
tempOffset = MCToastConfig.shared.text.offset
}
window.addSubview(mainView)
let main_y = tempOffset + superFrame.size.height/2
mainView.center = CGPoint.init(x: window.frame.size.width/2, y: main_y)
mainView.addSubview(label)
label.center = CGPoint.init(x: mainView.frame.size.width/2, y: mainView.frame.size.height/2)
windows.append(window)
MCToast.autoRemove(window: window, duration: duration, callback: callback)
return window
}
}
//
// MCToast.h
// Pods
//
// Created by Mccc on 2020/6/28.
//
#import <Foundation/Foundation.h>
FOUNDATION_EXPORT double MCToastVersionNumber;
FOUNDATION_EXPORT const unsigned char MCToastVersionString[];
//
// MCToast.swift
// MCToast
//
// Created by Mccc on 2019/4/19.
//
//待处理
//Wait状态,用json文件处理
// 多个状态更新的方案 (开始上传,正在上传,上传成功)
import Foundation
import UIKit
internal let sn_topBar: Int = 1001
internal let kScreenWidth = UIScreen.main.bounds.size.width
internal let kScreenHeight = UIScreen.main.bounds.size.height
public class MCToast: NSObject {
/// 管理所有的windows
internal static var windows = Array<UIWindow?>()
internal static let keyWindow = UIApplication.shared.keyWindow?.subviews.first as UIView?
internal static var timer: DispatchSource!
internal static var timerTimes = 0
private override init() { }
internal static func safeAreaInsets() -> (top: CGFloat, bottom: CGFloat) {
if #available(iOS 11.0, *) {
let inset = UIApplication.shared.delegate?.window??.safeAreaInsets
return (inset?.top ?? 0, inset?.bottom ?? 0)
} else {
return (0, 0)
}
}
}
extension MCToast {
public typealias MCToastCallback = () -> Void
public enum MCToastRespond {
/// Toast展示期间允许事件交互(等于respond)
case `default`
/// Toast展示期间不允许事件交互
case noRespond
/// Toast展示期间允许事件交互
case respond
/// Toast展示期间只允许导航条交互
case navBarRespond
}
}
extension MCToast {
/// 创建Window
/// - Parameters:
/// - respond: 交互类型
/// - frame: window的frame
static func createWindow(respond: MCToastRespond, frame: CGRect) -> UIWindow {
let window = UIWindow()
window.backgroundColor = UIColor.clear
switch respond {
case .respond, .default:
window.frame = frame
window.center = keyWindow!.center
case .noRespond:
window.frame = CGRect.init(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight)
case .navBarRespond:
let vc = UIViewController.current()
let rectNav = vc.navigationController?.navigationBar.frame
let maxY = rectNav?.maxY ?? 0
if vc.navigationController != nil && vc.navigationController?.navigationBar.isHidden == false {
window.frame = CGRect.init(x: 0, y: maxY, width: kScreenWidth, height: kScreenHeight - maxY)
} else {
window.frame = CGRect.init(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight)
}
}
window.windowLevel = UIWindow.Level.alert
window.isHidden = false
return window
}
/// 创建主视图区域
static func createMainView(frame: CGRect) -> UIView {
let mainView = UIView()
mainView.layer.cornerRadius = 10
mainView.backgroundColor = MCToastConfig.shared.background.color
mainView.frame = frame
mainView.alpha = 0.0
UIView.animate(withDuration: 0.2, animations: {
mainView.alpha = 1
})
return mainView
}
}
//
// MCToastConfig.swift
// MCComponentFunction_Example
//
// Created by Mccc on 2019/7/8.
// Copyright © 2019 CocoaPods. All rights reserved.
//
import Foundation
import UIKit
public class MCToastConfig: NSObject {
public static let shared = MCToastConfig()
/// 设置交互区域 默认导航栏下禁止交互
public var respond = MCToast.MCToastRespond.navBarRespond
/// 背景的设置
public var background = Background()
/// 状态Icon的设置
public var icon = Icon()
/// 文本的设置
public var text = Text()
/// 间距的设置
public var spacing = MainAreaSpacing()
/// 自动隐藏的时长
public var duration: CGFloat = 1.5
}
extension MCToastConfig {
public struct Background {
/// toast 的背景颜色
public var color: UIColor = UIColor.init(white: 0, alpha: 0.8)
/// toast的size
public var size: CGSize = CGSize.init(width: 135, height: 135)
}
public struct Icon {
/// toast icon的size
public var size: CGSize = CGSize.init(width: 50, height: 50)
public var successImage: UIImage?
public var failureImage: UIImage?
public var warningImage: UIImage?
}
public struct Text {
public var textColor: UIColor?
public var font: UIFont = UIFont.systemFont(ofSize: 15)
public var offset: CGFloat = (UIScreen.main.bounds.size.height / 2 - 120)
}
/// 主区域的间距
public struct MainAreaSpacing {
/// 外边距(toast距离屏幕边的最小边距)
public var margin: CGFloat = 55
/// 内边距(toast和其中的内容的最小边距)
public var padding: CGFloat = 15
}
}
//
// MCToastHelper.swift
// MCToast
//
// Created by Mccc on 2019/11/25.
//
import Foundation
import UIKit
@objc extension Bundle {
/**
* 加载指定bundle下的图片资源
* 在哪个pod下的哪个bundle下的image
*/
static func loadImage(_ imageName: String, from bundleName: String, in podName: String) -> UIImage? {
var associateBundleURL = Bundle.main.url(forResource: "Frameworks", withExtension: nil)
associateBundleURL = associateBundleURL?.appendingPathComponent(podName)
associateBundleURL = associateBundleURL?.appendingPathExtension("framework")
if associateBundleURL != nil {
let associateBunle = Bundle.init(url: associateBundleURL!)
associateBundleURL = associateBunle?.url(forResource: bundleName, withExtension: "bundle")
let bundle = Bundle.init(url: associateBundleURL!)
let scale = Int(UIScreen.main.scale)
// 适配2x还是3x图片
let name = imageName + "@" + String(scale) + "x"
if let path = bundle?.path(forResource: name, ofType: "png") {
let image1 = UIImage.init(contentsOfFile: path)
return image1
}
}
return nil
}
static func getBundleWithName(
_ bundleName: String,
inPod podName: String) -> Bundle? {
var associateBundleURL = Bundle.main.url(forResource: "Frameworks", withExtension: nil)
associateBundleURL = associateBundleURL?.appendingPathComponent(podName)
associateBundleURL = associateBundleURL?.appendingPathExtension("framework")
if associateBundleURL == nil {
print("获取bundle失败")
return nil
}
let associateBunle = Bundle.init(url: associateBundleURL!)
associateBundleURL = associateBunle?.url(forResource: bundleName, withExtension: "bundle")
let bundle = Bundle.init(url: associateBundleURL!)
return bundle
}
}
extension UIViewController {
/// 获取当前控制器
static func current() -> UIViewController {
let vc = UIApplication.shared.keyWindow?.rootViewController
return UIViewController.findBest(vc: vc!)
}
private static func findBest(vc: UIViewController) -> UIViewController {
if vc.presentedViewController != nil {
return UIViewController.findBest(vc: vc.presentedViewController!)
} else if vc.isKind(of: UISplitViewController.self) {
let svc = vc as! UISplitViewController
if svc.viewControllers.count > 0 {
return UIViewController.findBest(vc: svc.viewControllers.last!)
} else {
return vc
}
} else if vc.isKind(of: UINavigationController.self) {
let svc = vc as! UINavigationController
if svc.viewControllers.count > 0 {
return UIViewController.findBest(vc: svc.topViewController!)
} else {
return vc
}
} else if vc.isKind(of: UITabBarController.self) {
let svc = vc as! UITabBarController
if (svc.viewControllers?.count ?? 0) > 0 {
return UIViewController.findBest(vc: svc.selectedViewController!)
} else {
return vc
}
} else {
return vc
}
}
}
# Toast For Swift
## 概要说明
**MCToast** 是Swift版本的HUD库,提供了显示纯文本的Toast,带有状态图片的Toast,带有loading样式的Toast。
主要优点:
* Swift语言实现的Toast交互功能库。
* MCToast内部控制显示在主线程中,保证了线程安全性。
* 提供了多种使用方式,方便快捷。
* 支持UI的高度自定义。配置toast的小图标,文字大小和颜色等
* 内部处理了多个toast提示重叠显示的问题。
Demo地址
[https://github.com/mancongiOS/MCToast](https://github.com/mancongiOS/MCToast)
## 样例展示
![示例1](https://github.com/mancongiOS/MCToast/blob/master/gif1-min.gif)
![示例2](https://github.com/mancongiOS/MCToast/blob/master/gif2-min.gif)
![示例3](https://github.com/mancongiOS/MCToast/blob/master/all.png)
#
# 使用
#### 支持cocoPods
```
pod 'MCToast'
```
#### 使用
* 显示纯文本
```
// 可以这样用
self.mc_text("这是一个纯文本的展示")
// 也可以这样用
MCToast.mc_text("这是一个很长长长长长长长长长长长长长长长的纯文本的展示")
// 设置offset
MCToast.mc_text("居中显示", offset: 0)
```
* 带状态的Toast
```
/// 成功的Toast
MCToast.mc_success("可能出现的长文本提示长文本内容")
/// 失败的Toast
MCToast.mc_failure("失败")
/// 警告的Toast
MCToast.mc_warning("警告")
/// 自定义的状态Toast
MCToast.mc_codeSuccess()
extension MCToast {
/// 发送验证码成功
public static func mc_codeSuccess() {
let image = UIImage.init(named: "codesend")
MCToast.showStatus(nil, text: "发送验证码成功", iconImage: image, duration: 2, respond: .respond)
}
}
```
* loading
```
/// 系统的loading
MCToast.mc_loading()
/// 自定义的帧动画loading
MCToast.mc_loading(imageNames: images)
/// Json动画的loading (集成了Lottie库)
let animation = Animation.named("JSON动画")
MCToast.mc_loading(animation: animation)
```
* 其他更详细的使用请查看[Demo](https://github.com/mancongiOS/MCToast)
#### 配置Toast的UI显示
如果你需要自定义UI样式,可以通过设置MCToastConfig达到你的目的。
```
public class MCToastConfig: NSObject {
public static let shared = MCToastConfig()
/// 设置交互区域 默认导航栏下禁止交互
public var respond = MCToast.MCToastRespond.navBarRespond
/// 背景的设置
public var background = Background()
/// 状态Icon的设置
public var icon = Icon()
/// 文本的设置
public var text = Text()
/// 间距的设置
public var spacing = MainAreaSpacing()
/// 自动隐藏的时长
public var duration: CGFloat = 1.5
}
extension MCToastConfig {
public struct Background {
/// toast 的背景颜色
public var color: UIColor = UIColor.init(white: 0, alpha: 0.8)
/// toast的size
public var size: CGSize = CGSize.init(width: 135, height: 135)
}
public struct Icon {
/// toast icon的size
public var size: CGSize = CGSize.init(width: 50, height: 50)
public var successImage: UIImage?
public var failureImage: UIImage?
public var warningImage: UIImage?
}
public struct Text {
public var textColor: UIColor?
public var font: UIFont = UIFont.systemFont(ofSize: 15)
public var offset: CGFloat = (UIScreen.main.bounds.size.height / 2 - 120)
}
/// 主区域的间距
public struct MainAreaSpacing {
/// 外边距(toast距离屏幕边的最小边距)
public var margin: CGFloat = 55
/// 内边距(toast和其中的内容的最小边距)
public var padding: CGFloat = 15
}
}
```
示例:
```
/// 背景框的大小
MCToastConfig.shared.background.size = CGSize.init(width: 200, height: 200)
/// icon的大小
MCToastConfig.shared.icon.size = CGSize.init(width: 150, height: 150)
/// 不同状态下的Toast的icon图片
MCToastConfig.shared.icon.successImage = UIImage.init(named: "code")
```
# 说明
1. 由于Toast是展示在Window上的,页面返回正在显示的Toast并不会消失。可以在页面的生命周期内调用MCToast.mc_remove()方法达到页面返回消失的目的。
......@@ -7,7 +7,10 @@ PODS:
- Adjust/Core (4.33.2)
- HandyJSON (5.0.2)
- IQKeyboardManager (6.5.10)
- lottie-ios (3.2.3)
- MBProgressHUD (1.2.0)
- MCToast (0.1.0):
- lottie-ios
- SDCycleScrollView (1.82):
- SDWebImage (>= 5.0.0)
- SDWebImage (5.14.2):
......@@ -22,6 +25,7 @@ DEPENDENCIES:
- HandyJSON
- IQKeyboardManager
- MBProgressHUD
- MCToast
- SDCycleScrollView
- SDWebImage
- SnapKit
......@@ -31,7 +35,9 @@ SPEC REPOS:
- Adjust
- HandyJSON
- IQKeyboardManager
- lottie-ios
- MBProgressHUD
- MCToast
- SDCycleScrollView
- SDWebImage
- SnapKit
......@@ -58,11 +64,13 @@ SPEC CHECKSUMS:
Adjust: 554c87d1b6799efa8169d34166b2a12862bf002c
HandyJSON: 9e4e236f5d2dbefad5155a77417bbea438201c03
IQKeyboardManager: 45a1fa55c1a5b02c61ac0fd7fd5b62bb4ad20d97
lottie-ios: c058aeafa76daa4cf64d773554bccc8385d0150e
MBProgressHUD: 3ee5efcc380f6a79a7cc9b363dd669c5e1ae7406
MCToast: accd8b0d4653bcd6b3b1a9770802c2358614e6a5
SDCycleScrollView: a0d74c3384caa72bdfc81470bdbc8c14b3e1fbcf
SDWebImage: b9a731e1d6307f44ca703b3976d18c24ca561e84
SnapKit: fe8a619752f3f27075cc9a90244d75c6c3f27e2a
PODFILE CHECKSUM: c5983d16970d9d4e9e25d2617a99901bf1ffd9a2
PODFILE CHECKSUM: 2c02dcc29a9ee1c95e1075175ad5362ae5816532
COCOAPODS: 1.11.3
This source diff could not be displayed because it is too large. You can view the blob instead.
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论