FZTextFocuser
FZTextFocuser
允许在 tvOS 中显示可聚焦的文本,并提供选项来自定义聚焦状态,可以是突出显示整个文本或仅突出显示部分。
如何使用
要使用 FZTextFocuser
,首先将一个实例添加到您的视图中,然后传递一个格式化字符串给它,并设置定义聚焦文本展示方式的属性。
let textFocuser = FZTextFocuser(frame: self.view.frame)
self.view.addSubview(textFocuser)
textFocuser.attributedString = NSAttributedString(string: "Test String", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 40), NSAttributedString.Key.foregroundColor: UIColor.black])
textFocuser.focusedBackgroundColor = UIColor.red // this will be applied to the entire view when focused
textFocuser.addFocusableText("String", textColor: .yellow, backgroundColor: .blue, cornerRadius: 5) // this will apply only to the specified string
还需要确保实现 FZTextFocuserDelegate
协议,并将您的 FZTextFocuser
实例的代理属性设置为在用户点击文本时收到通知
示例
要运行示例项目,首先克隆仓库,然后从示例目录运行 pod install
安装
您可以使用 CocoaPods (https://cocoapods.org.cn/) 安装 FZTextFocuser
。如果您项目中还没有配置 CocoaPods,请参阅 CocoaPods 指南 (https://guides.cocoapods.org.cn/using/using-cocoapods.html)。
接下来,将库添加到您的 Podfile
pod 'FZTextFocuser'
然后,运行以下命令
$ pod install
一旦 CocoaPods 与您的项目集成,请确保始终通过 .xcworkspace
文件而不是 .xcodeproj
文件运行您的项目。
或者,您可以直接下载源代码,并将文件 FZTextFocuser.swift
添加到您的项目中。
要求
tvOS 9.0+
作者
gutenbergn, [email protected]
许可证
FZTextFocuser遵循MIT许可证。更多信息请参阅LICENSE文件。