要运行示例项目,克隆存储库,打开并运行 Example 模式。
ARC
iOS8
MFNoticeLabel 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod "MFNoticeLabel"
从导入开始
import MFNoticeLabel
创建并自定义您的标签:(添加通知消息并定义选择类型)
label.frame = CGRect(x: 0, y: 0, width: 300, height: 40)
label.center = self.view.center
label.textAlignment = .Center
label.text = "Something something"
label.noticeMessage = "Longer than something something because it is a description and stuff"
label.textColor = UIColor.blueColor()
label.noticeSelectionType = MFNoticeLabelSelectionType.LongPress
label.longPressDelegate = self
view.addSubview(label)
确保正确定义您想要使用的选择类型
label.noticeSelectionType = MFNoticeLabelSelectionType.LongPress
您可以选择实现长按(见上面)或点击代理协议
public protocol MFNoticeLabelTapDelegate: class
{
func didSelectLabel(text: String)
}
public protocol MFNoticeLabelLongPressDelegate: class
{
func didLongPressLabel(text: String)
func longPressEnded()
}
或者可以定义点击处理程序或长按开始/结束处理程序
public func handleTap(handler:(String) -> ()){}
public func handleLongPressStarted(handler:(String) -> ()){}
public func handleLongPressEnded(handler:() -> ()){}
您可以使用自己的方式展示通知消息,或者可以使用内置的类似弹窗的控制(可自定义:背景色、弹窗标题标签和弹窗描述标签已被公开)
let button2 = MFNoticeAlertButton(title: "Dismiss", style: MFNoticeAlertButtonStyle.Cancel, action: {
self.dismissViewControllerAnimated(true, completion: nil)
})
let button1 = MFNoticeAlertButton(title: "Ok", style: MFNoticeAlertButtonStyle.Default, action: {
self.dismissViewControllerAnimated(true, completion: nil)
})
let alertVC = MFNoticeAlertController(title: "Some title", description: "A little bit of text just to give you a taste on what it may look like, little bit of text just to give you a taste on what it may look like", image: UIImage(named: "phone"))
alertVC.addButtons([button1, button2])
self.presentViewController(alertVC, animated: true, completion: nil)
Mateusz Fidos, [email protected]
MFNoticeLabel 在 MIT 许可证下提供。有关更多信息,请参阅 LICENSE 文件。