ios - 如何使用 Swift 在我的应用程序中使用 SwiftMessage cocoapod?
问题描述
在我的场景中,我正在尝试将卡片弹出顶部(如吐司消息)集成到我的应用程序中。因此,我决定将SwiftMeesage
cocoa pod 集成到我的应用程序中。我没有得到适当的逐步集成程序。下面的步骤我已经完成,但我需要进一步澄清。
https://github.com/SwiftKickMobile/SwiftMessages
- 已安装
pod 'SwiftMessages
- 已创建
CardView.xib
- CardView.xib 类和模块 我需要提供什么?
如何从多个视图控制器调用此 xib。我正在启用按钮,所以我需要处理按钮操作。根据存储库文档信息类和模块信息未正确提供。请提供集成此模块的步骤。
自定义类 UIView
guard let view = Bundle.main.loadNibNamed("ToastView.", owner: nil, options: nil)?.first as? ToastView else { return }
var config = SwiftMessages.defaultConfig
config.presentationContext = .window(windowLevel: UIWindow.Level.statusBar)
config.duration = SwiftMessages.Duration.seconds(seconds: 5) // show in 5 seconds for example
SwiftMessages.show(config: config, view: view)
解决方案
我建议您使用自定义视图而不是默认视图,CardView
然后您可以进行更多自定义。
代码可能是这样的:
guard let view = Bundle.main.loadNibNamed("YourCustomView.", owner: nil, options: nil)?.first as? YourCustomView. else { return }
var config = SwiftMessages.defaultConfig
config.presentationContext = .window(windowLevel: UIWindow.Level.statusBar)
config.duration = SwiftMessages.Duration.seconds(seconds: 5) // show in 5 seconds for example
SwiftMessages.show(config: config, view: view)
如果您不想使用自定义视图
let view = MessageView.viewFromNib(layout: .cardView)
// Customize icon, title, body... here
SwiftMessages.show(config: config, view: view)
推荐阅读
- python - 将列添加到具有不同值的指定索引处的 csv 文件
- git - Fixup git after a failed filter-branch --tree-filter
- jquery - 替换标签中包含输入的文本,而不影响输入
- ruby-on-rails - has_many through associations find count of physician.id
- ios - How to optimize memory for very long navigation stack of UIViewControllers
- ruby-on-rails - One to Many To Many: One user has many store. One store has many products
- java - Hibernate 事务管理比较
- javascript - 使用 Vanilla Javascript 关闭多个弹出消息框
- javascript - 如何在 javascript 中使用 map 函数迭代嵌套字典
- javascript - 比较键后如何将对象列表转换为嵌套对象