TvOSMoreButton 1.4.1

TvOSMoreButton 1.4.1

测试测试
语言语言 SwiftSwift
许可证 MIT
发布最新发布2022年4月
SPM支持 SPM

Chris Goldsby 维护。



  • 作者
  • Chris Goldsby

TvOSMoreButton

📺一个 tvOS 按钮,用于截断长文本并添加 '... More'。

TvOSMoreButton 是一个简单的视图,旨在模仿苹果的 "... 更多" 按钮的行为;如电影应用中所示。

特性

如果文本太长而无法在按钮范围内显示,则文本将被截断并添加 '... 更多'。

默认情况下,如果文本被截断,按钮将是可聚焦的。如果文本没有被截断,则按钮将不可聚焦。

但是,您可以将 focusableMode 设置为 focusable(_ isFocusable: Bool) 以更改聚焦行为。这种模式将强制按钮始终聚焦或从不聚焦。

当按钮聚焦时,按下 Apple TV 遥控器的选择键将触发回调。

大部分的 UI 属性都是可配置的,例如:

  • 按钮文本
  • 省略号文本;默认为 '...'。
  • 尾部文本;默认为 "更多"。
  • 尾部文本的颜色和字体
  • 按钮文本的颜色和字体
  • 阴影和半径
  • 等等😉

要求

  • tvOS 9.0+
  • Xcode 9

安装

CocoaPods

CocoaPods 是一个用于 Cocoa 项目的依赖管理器。您可以使用以下命令安装它

$ gem install cocoapods

要使用 CocoaPods 将 TvOSMoreButton 集成到您的 Xcode 项目中,在您的 Podfile 中指定它

source 'https://github.com/CocoaPods/Specs.git'
platform :tvos, '9.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'TvOSMoreButton', '~> 1.4.1'
end

然后,运行以下命令

$ pod install

Carthage

Carthage 是一个去中心化的依赖管理器,它会构建您的依赖并提供二进制框架。

您可以使用 Homebrew 使用以下命令安装 Carthage

$ brew update
$ brew install carthage

要使用 Carthage 将 TvOSMoreButton 集成到您的 Xcode 项目中,在您的 Cartfile 中指定它

github "cgoldsby/TvOSMoreButton" ~> 1.4.1

运行 carthage update 以构建框架并将构建的 TvOSMoreButton.framework 拖入您的 Xcode 项目。

使用示例

请查看示例工作空间以获取更多信息。

    import TvOSMoreButton

    private func setUpUI() {
        tvOSMoreButton.text = // Super long text
        tvOSMoreButton.buttonWasPressed = {
            [weak self] text in
            self?.moreButtonWasPressed(text: text)
        }
    }

    private func moreButtonWasPressed(text: String?) -> Void {
        // Do something. May I suggest using TvOSTextViewerViewController
        // to display the text in a full screen view!
        let viewController = TvOSTextViewerViewController()
        viewController.text = text
        viewController.textColor = .white
        viewController.textEdgeInsets = UIEdgeInsets(top: 100, left: 250, bottom: 100, right: 250)
        present(viewController, animated: true)
    }

如果您想显示一个仅包含文本的全屏视图,请务必查看 @dcordero 推出的精彩的 TvOSTextViewer。太棒了!

贡献

我们希望您为 TvOSMoreButton 做出贡献,有关更多信息,请查看 LICENSE 文件。您可以提交任何问题或 PR。❤️

元数据

特别感谢@mona-zsh关于字符串截断的优秀文章。

Chris Goldsby – @goldsbychris

在MIT许可证下分发。有关更多信息,请参阅LICENSE文件。