CopyableLabel 4.2.0

CopyableLabel 4.2.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最新版本2018 年 9 月
SPM支持 SPM

Donatas Stundys 维护。




  • Donatas Stundys

CopyableLabel

UILabel 扩展,以启用复制功能

Screenshot

使用方法

import CopyableLabel

let label = UILabel()
label.copyable = true

或者在 Interface Builder 中将可复制属性设置为 true。

如果另一个对象(例如 UIViewController)需要知道哪个 CopyableLabel 触发了 UIMenuController(即展示了“复制”气泡,注册该对象以便获得 Notification.name.copyableLabelDidShowCopyMenu 通知

NotificationCenter.default.addObserver(self, selector: #selector(receivedCopyableLabelNotification(_:)), name: .copyableLabelDidShowCopyMenu, object: nil)

注册的对象将接收到一个包含已发送通知的 CopyableLabel 引用的 Notification。

@objc func receivedCopyableLabelNotification(_ notification:NSNotification) {
	if let label = notification.object as? UILabel {
		print(label.text!)
	}
}

UIMenuController 确实发送了 UIMenuController.didShowMenuNotification,但是该通知不提供任何额外信息(例如,哪些 UI 元素发送了通知,菜单在哪里等)。

如果需要知道何时关闭菜单,请注册 UIMenuController 会 Hide 或 didHide 通知。

要求

iOS 9 或更高版本

安装

CocoaPods

CopyableLabel 可通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile 中

pod "CopyableLabel"

Carthage

您可以通过将 Carthage 添加到 Cartfile 来使用 Carthage 安装 CopyableLabel

github "weby/CopyableLabel"

作者

Donatas Stundys, [email protected]

许可协议

CopyableLabel 采用 MIT 许可协议。更多详情请查看 LICENSE 文件。