Swift 弹框 第三方库 Toast-Swift(弹框提示)

GitHub 上搜索这个库,然后下载zip文件,找到如下文件,拖到项目中就可以使用
在这里插入图片描述
先看效果图1
在这里插入图片描述
这个弹框显示位置可以设置在屏幕中心,底部,头部都可以,代码如下:

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

先看效果图2
在这里插入图片描述
代码如下:

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

先看效果图3
在这里插入图片描述
代码如下:

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

此框架的用法不仅仅如此

  • 能展示图文
  • 能接受点击事件
  • 能展示自定义视图
  • 能自定义样式
 
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)

自定义样式

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

猜你喜欢

转载自blog.csdn.net/weixin_43259805/article/details/123278264