SwiftSwift开发

Swift必备第三方库-Toast-Swift(弹框)

2021-03-10  本文已影响0人  MR_詹

github地址

makeToast 展示弹框

  • 能展示图文
  • 能接收点击事件
// basic usage
self.view.makeToast("This is a piece of toast")

// toast with a specific duration and position
self.view.makeToast("This is a piece of toast", duration: 3.0, position: .top)

// toast presented with multiple options and with a completion closure
self.view.makeToast("This is a piece of toast", duration: 2.0, point: CGPoint(x: 110.0, y: 110.0), title: "Toast Title", image: UIImage(named: "toast.png")) { didTap in
    if didTap {
        print("completion from tap")
    } else {
        print("completion without tap")
    }
}

showToast 展示自定义视图

// display any view as toast
self.view.showToast(myView)

隐藏弹框

// immediately hides all toast views in self.view
self.view.hideAllToasts()

Loading弹框

// display toast with an activity spinner
self.view.makeToastActivity(.center)

自定义样式

/// makeToast 方法 样式style属性都有一个默认值,由单例类ToastManager管理
makeToast(_ message: String?, duration: TimeInterval = ToastManager.shared.duration, point: CGPoint, title: String?, image: UIImage?, style: ToastStyle = ToastManager.shared.style, completion: ((_ didTap: Bool) -> Void)?)


// create a new style
var style = ToastStyle()
// this is just one of many style options
style.messageColor = .blue

/// 单独设置弹框样式
// present the toast with the new style
self.view.makeToast("This is a piece of toast", duration: 3.0, position: .bottom, style: style)

/// 全局配置统一样式
// or perhaps you want to use this style for all toasts going forward?
// just set the shared style and there's no need to provide the style again
ToastManager.shared.style = style
self.view.makeToast("This is a piece of toast") // now uses the shared style

/// toast弹框点击隐藏
// toggle "tap to dismiss" functionality
ToastManager.shared.isTapToDismissEnabled = true

/// 多个弹框是否重叠
// toggle queueing behavior
ToastManager.shared.isQueueEnabled = true
上一篇下一篇

猜你喜欢

热点阅读