安装
1.Xcode中,点击Project页面下方的+号(Add Package Dependency)
2.右上角搜索栏输入网址 https://github.com/SwiftKickMobile/SwiftMessages 点击Add Package即可安装
使用
1.在工程开头导入SwiftMessage
import SwiftMessages
2.创建一个function以调用SwiftMessage
title:标题
body:内容
iconText:文本构成的Emoji
func pop(){
AudioServicesPlaySystemSound(1519)
let view = MessageView.viewFromNib(layout: .cardView)
// Theme message elements with the warning style.
view.configureTheme(.info)
// Add a drop shadow.
view.configureDropShadow()
// Set message title, body, and icon. Here, we're overriding the default warning
// image with an emoji character.
//隐藏按钮
view.button?.isHidden = true
let iconText = ["✔️"].randomElement()!
view.configureContent(title: "收到!", body: "添加完成", iconImage: .none, iconText: iconText, buttonImage: UIImage(systemName:"checkmark"), buttonTitle: .none, buttonTapHandler: .none)
// Increase the external margin around the card. In general, the effect of this setting
// depends on how the given layout is constrained to the layout margins.
view.layoutMarginAdditions = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)
// Reduce the corner radius (applicable to layouts featuring rounded corners).
(view.backgroundView as? CornerRoundingView)?.cornerRadius = 10
// Show the message.
SwiftMessages.show(view: view)
}
3.在需要的地方调用即可
pop()