PVShow Message
关注我:@vaberer
我喜欢 ★。别忘了星标这个非常便利的库。
一个简单的库,通过触摸事件显示自定义消息。可完全通过属性自定义。如果正在显示任何消息,并且想显示另一条消息,它将等待上一条消息消失。
在竖直方向、横屏模式和配合约束下工作得非常好。
要求
- iOS 8.0+
- Xcode 6.3
安装
CocoaPods
CocoaPods 是 Cocoa 项目的依赖管理器。
CocoaPods 0.36 添加了对 Swift 和嵌入式框架的支持。您可以使用以下命令来安装它:
$ gem install cocoapods
要使用 CocoaPods 将 PVShow Message 集成到您的 Xcode 项目中,请在您的 Podfile
中指定它
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'PVShow-Message', '~> 1.3.0'
然后,运行以下命令
$ pod install
别忘了将库导入到你想使用此库的swift文件中
import PVShow_Message
手动
- 将
PVShowMessage.swift
文件复制到你的项目中
使用方法
显示消息
PVShowMessage.instance.showMessage(text: "All data has been updated\nYou have fresh data")
使用以下属性自定义您的消息视图
PVShowMessage.cBackgroundColor = .black
PVShowMessage.cBorderColor = .clear
PVShowMessage.cBorderWidth = 3
PVShowMessage.cCornerRadius = 0
PVShowMessage.cFont = UIFont.systemFont(ofSize: 20)
PVShowMessage.cTextColor = .white
PVShowMessage.cPositionFromEdge = 200
PVShowMessage.cExtraShowTimeForMessage = 3
PVShowMessage.cInitialPosition = .top
PVShowMessage.cAnimationDuration = 1.5
通过代理进行触摸事件处理
您可以将任何标识符附加到消息视图,并且通过代理方法返回给您
PVShowMessage.instance.showMessage(text: "My Text", identifier: "identifier")
在 viewWillAppear
方法中告诉消息视图谁是代理
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
PVShowMessage.instance.delegate = self
}
实现 PVShowMessageDelegate
func didTapToMessage(identifier: String?) {
print("Tapped to a message with identifier: \(identifier)")
}
从队列中删除消息
将要显示的所有消息都将从队列中删除
PVShowMessage.instance.removeAllMessages()
作者
帕特里克·瓦贝雷尔,[email protected]
领英
许可
PVShow Message遵循MIT许可。更多信息请参阅LICENSE文件。