Code Monkey home page Code Monkey logo

tvosmorebutton's Introduction

TvOSMoreButton

๐Ÿ“บ A tvOS button which truncates long text with '... More'.

The TvOSMoreButton is a simple view which aims to mirror the behavior of Apple's "... More" button; as seen in the Movie App.

Features

If the text is too long to fit with in the button bounds then the text will be truncated and '... More' will be appended.

By default, if the text is truncated the button will be focusable. If the text is not truncated then the button will not be focusable.

However, you can set focusableMode to manual(_ isFocusable: Bool) to alter the focus behavior. This mode will force the button to be always be focused or never be focused.

When the button is focused, pressing select on the Apple TV remote will trigger a callback.

The majority of the UI properties are configurable; like

  • the button text
  • ellipse text; defaults to '...'
  • trailing text; defaults to "More"
  • trailing text color and font
  • the button text color and font
  • shadows and radius
  • and More ๐Ÿ˜‰

Requirements

  • tvOS 9.0+
  • Xcode 9

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate TvOSMoreButton into your Xcode project using CocoaPods, specify it in your Podfile:

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

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

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate TvOSMoreButton into your Xcode project using Carthage, specify it in your Cartfile:

github "cgoldsby/TvOSMoreButton" ~> 1.2.2

Run carthage update to build the framework and drag the built TvOSMoreButton.framework into your Xcode project.

Usage example

Please check out the Example workspace for more details.

    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)
    }

If you would like to display a fullscreen view with just the text then definitely check out @dcordero's awesome TvOSTextViewer. So good!

Contribute

We would love for you to contribute to TvOSMoreButton, check the LICENSE file for more info. Feel free to submit any issues or PRs. โค๏ธ

Meta

Special thanks @mona-zsh for her fantastic article on String Truncation.

Chris Goldsby โ€“ @goldsbychris

Distributed under the MIT license. See LICENSE for more information.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.