//
// SwiftMessageManager.swift
// showAlertMessage
//
// Created by 宋金委 on 16/8/30.
// Copyright © 2016年 SKing. All rights reserved.
//
import UIKit
import SwiftMessages
//布局样式
enum LayoutType : String{
case MessageView
case CardView
case TabView
case StatusLine
case MessageViewIOS8
}
//消息类型
public enum ThemeType : String {
case Info
case Success
case Warning
case Error
}
class SwiftMessageManager: NSObject {
/**
生产 status 的抽取方法
- parameter layoutType: 布局样式
- parameter themeType: 消息类型
- parameter iconImageType: 消息图标的类型
- parameter presentationStyleType: 模态的位置
- parameter title: 标题
- parameter body: 说明文字
- parameter isHiddenBtn: 是否 隐藏 按钮
- parameter seconds: 显示的时间
*/
class func showMessage(layoutType:LayoutType, themeType :ThemeType ,iconImageType : IconStyle, presentationStyleType :SwiftMessages.PresentationStyle, title :String,body:String, isHiddenBtn: Bool,seconds :NSTimeInterval) {
var view = MessageView.viewFromNib(layout: .MessageView)
switch layoutType {
case .MessageView:
print("已经在初始化的时候执行过")
case .CardView:
view = MessageView.viewFromNib(layout: .CardView)
case .TabView:
view = MessageView.viewFromNib(layout: .TabView)
case .StatusLine:
view = MessageView.viewFromNib(layout: .StatusLine)
default:
view = MessageView.viewFromNib(layout: .MessageViewIOS8)
}
view.configureContent(title: title, body: body, iconImage: nil, iconText: nil, buttonImage: nil, buttonTitle: "隐藏", buttonTapHandler: { _ in SwiftMessages.hide() })
switch themeType {
case .Success:
view.configureTheme(.Success, iconStyle:iconImageType)
case .Warning:
view.configureTheme(.Warning, iconStyle:iconImageType)
case .Error:
view.configureTheme(.Error, iconStyle:iconImageType)
default:
view.configureTheme(.Info, iconStyle:iconImageType)
}
view.button?.hidden = isHiddenBtn;
var infoConfig = SwiftMessages.Config()
infoConfig.presentationStyle = presentationStyleType
infoConfig.duration = .Seconds(seconds: seconds)
SwiftMessages.show(config: infoConfig, view: view)
}
}
调用
//
// ViewController.swift
// showAlertMessage
//
// Created by HMC on 16/8/30.
// Copyright © 2016年 SKing. All rights reserved.
//
import UIKit
import SwiftMessages
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func clickBtn(sender: AnyObject) {
switch (sender as! UIButton).tag {
case 0:
print("消息")
SwiftMessageManager.showMessage(.MessageView, themeType:.Info, iconImageType:.Light, presentationStyleType:.Top, title: "信息", body: "我成功了", isHiddenBtn: true, seconds: 5)
case 1:
print("成功")
SwiftMessageManager.showMessage(.MessageView, themeType:.Success, iconImageType:.Light, presentationStyleType:.Top, title: "信息", body: "我成功了", isHiddenBtn: false, seconds: 5)
case 2:
print("错误")
SwiftMessageManager.showMessage(.MessageView, themeType:.Error, iconImageType:.Light, presentationStyleType:.Top, title: "信息", body: "我失败了", isHiddenBtn: true, seconds: 5)
case 3:
print("警告")
SwiftMessageManager.showMessage(.MessageView, themeType:.Warning, iconImageType:.Light, presentationStyleType:.Top, title: "信息", body: "我成功了", isHiddenBtn: true, seconds: 1)
default:
print("自定义")
}
}
}
代码在这 点我