Swift pop-up third-party library Toast-Swift (pop-up prompt)

Search for this library on GitHub, then download the zip file, find the following file, drag it into the project, you can use it
insert image description here
first Look at the effect Figure 1
insert image description here
The display position of this pop-up box can be set in the center of the screen, at the bottom, and in the head. The code is as follows:

 kWindow.makeToast("读取完成", duration: 2, position: .center)

First look at the effect picture 2 The
insert image description here
code is as follows:

//显示
kWindow.makeToastActivity(.center)
//隐藏
kWindow.hideToastActivity()

First look at the effect picture 3 The
insert image description here
code is as follows:

  kWindow.makeToast("读取完成", duration: 2, position: .center, title: "这是标题", image: UIImage.init(named: "tabbar_middle_add"))

The usage of this framework is not only

  • Can display graphics
  • Can accept click events
  • Ability to display custom views
  • Customizable style
 
self.view.makeToast("This is a piece of toast")
 
self.view.makeToast("This is a piece of toast", duration: 3.0, position: .top)
//接受点击事件
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")
    }
}
// 添加自定义视图
self.view.showToast(myView)

custom style

/// 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

END

Guess you like

Origin blog.csdn.net/weixin_43259805/article/details/123278264