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

Overview

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 '
   
    '
    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:

1.2.2 ">
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.

Comments
  • Error Type 'NSAttributedStringKey' (aka 'NSString') has no member 'foregroundColor'

    Error Type 'NSAttributedStringKey' (aka 'NSString') has no member 'foregroundColor'

    We have fount error:

    1. Type 'NSAttributedStringKey' (aka 'NSString') has no member 'foregroundColor'
    2. Type 'NSAttributedStringKey' (aka 'NSString') has no member 'foregroundColor'

    in " TvOSMoreButton.swift"

    Can you help me to resolve it ?

    help wanted 
    opened by aminmahdi 5
  • Incorrectly displayed trailing text

    Incorrectly displayed trailing text

    What did you do

    Set the text more than can be reflected

    What did you expect to happen?

    The test is displayed partially, and trailing text is displayed completely


    Text text text text text text text text text text text text text te xt text text text text text text text text text text text text text
    text text text text text text text text text text text tex... More


    What happened instead?

    The test is displayed partially, and trailing text is displayed partially


    Text text text text text text text text text text text text text te xt text text text text text text text text text text text text text
    text text text text text text text text text text text tex... Mor...


    Why did it happen?

    Text and trailing text have different attributes, so you need to use NSMutableAttributedString to calculate the height.

    func willFit(to size: CGSize,
                     ellipsesString: String = "",
                     trailingText: String = "",
                     attributes: [NSAttributedString.Key: Any],
                     trailingTextAttributes: [NSAttributedString.Key: Any]) -> Bool {
    
            let attributedString = NSMutableAttributedString(string: self + ellipsesString, attributes: attributes)
            let attributedTrailingString = NSAttributedString(string: trailingText, attributes: trailingTextAttributes)
            attributedString.append(attributedTrailingString)
            
            let boundedSize = CGSize(width: size.width, height: .greatestFiniteMagnitude)
            let options: NSStringDrawingOptions = [.usesLineFragmentOrigin, .usesFontLeading]
            let boundedRect = attributedString.boundingRect(with: boundedSize,
                                                            options: options,
                                                            context: nil)
            return boundedRect.height <= size.height
        }
    
    bug 
    opened by srGritsuk 3
  • Build fails while compiling for tvOS 11

    Build fails while compiling for tvOS 11

    Hi,

    Since my Apple TV updated itself to tvOS 11, I've been trying to make PopcornTimeTV work again. Unfortunately, during compilation this version of TvOSMoreButton causes two errors:

    • Type 'NSAttributedStringKey' (aka 'NSString') has no member 'foregroundColor'
    • Cannot convert value of type '[NSAttributedStringKey : Any]' (aka 'Dictionary<NSString, Any>') to expected argument type '[String : Any]?'

    Any idea how to fix it? I'm still trying to find something online, but it's too specific.

    Thank you very much, Gustavo

    EDIT: Using the previous version it compiled just fine, but it would be nice to understand how to fix the latest version.

    help wanted 
    opened by gustavolessa23 3
  • Button stays in focused appearance when it isn't focused

    Button stays in focused appearance when it isn't focused

    What did you do

    Focus on TvOSMoreButton Press remote touch surface to select button and hold, do not release remote "button" While remote button still not released move focus to another focusable element. Another element is focused Release remote button

    What did you expect to happen?

    After switching focus to another element, TvOSMoreButton should stay in unfocused appearance - no highlight

    What happened instead?

    After focus switched to another element, TvOSMoreButton becomes highlighted


    I'm sure the reason is that method applyPressUpAppearance() called without checking isFocused == true

    bug 
    opened by OPoliukhovych 2
  • Resource Bundle target is named

    Resource Bundle target is named "TvOSMoreButton-TvOSMoreButton"?

    When integrating TvOSMoreButton into my project, I see that apart from "TvOSMoreButton" it creates an extra target called "TvOSMoreButton-TvOSMoreButton".

    It also happens in the Example project in this repo:

    screen shot 2017-12-01 at 10 39 35 question 
    opened by dcordero 2
  • Installation Section

    Installation Section

    Hey, your library is really interesting.

    The only problem I found was the README.md, which lacks an Installation Section I created this iOS Open source Readme Template so you can take a look on how to easily create an Installation Section If you want, I can help you to organize the lib.

    What are your thoughts? ๐Ÿ˜„

    opened by lfarah 2
  • Implemented focusable mode (auto, manual).

    Implemented focusable mode (auto, manual).

    The ability to manually set isFocusable: auto, always true, always false. Now the focus is resolved automatically to true, if the text does not fit in the label.

    opened by srGritsuk 1
  • Swift 4.2?

    Swift 4.2?

    Are there any near term plans to support Swift 4.2 and Xcode 10? The two issues that are stopping me are operators that have been removed (such as &~ and |=). Other remaining issues are mostly renames such as NSAttributedStringKey to NSAttributedString.Key.

    opened by robbiet480 1
  • 'NSAttributedStringKey' on xCode 8.3.3

    'NSAttributedStringKey' on xCode 8.3.3

    Hi!

    I'm using xCode 8.3.3 to build a PopcornTimeTV app for tvOS 10.2.2. The problem is with 'NSAttributedStringKey' (use of undeclared type). Apparently, it's an iOS 11 implementation and xCode doesn't recognize it. It's on String+Truncation.swift and TvOSMoreButton.swift. Maybe it was already updated for xCode 9? Do you know how can I "fix" it?

    Thanks very much!

    opened by gustavolessa23 1
  • Reproducing TVML like _TVButtonLockup in UIKit?

    Reproducing TVML like _TVButtonLockup in UIKit?

    Hi ๐Ÿ‘‹๐Ÿป

    Really nice project! Definitely going to be using this in a project we're working on. Thought I'd ask but do you have any plans to recreate _TVButtonLockup buttons in UIKit with working labels as the way it's been done in TVML?

    tvml

    opened by RefusedFlow 1
  • Bump tzinfo from 1.2.5 to 1.2.10

    Bump tzinfo from 1.2.5 to 1.2.10

    Bumps tzinfo from 1.2.5 to 1.2.10.

    Release notes

    Sourced from tzinfo's releases.

    v1.2.10

    TZInfo v1.2.10 on RubyGems.org

    v1.2.9

    • Fixed an incorrect InvalidTimezoneIdentifier exception raised when loading a zoneinfo file that includes rules specifying an additional transition to the final defined offset (for example, Africa/Casablanca in version 2018e of the Time Zone Database). #123.

    TZInfo v1.2.9 on RubyGems.org

    v1.2.8

    • Added support for handling "slim" format zoneinfo files that are produced by default by zic version 2020b and later. The POSIX-style TZ string is now used calculate DST transition times after the final defined transition in the file. The 64-bit section is now always used regardless of whether Time has support for 64-bit times. #120.
    • Rubinius is no longer supported.

    TZInfo v1.2.8 on RubyGems.org

    v1.2.7

    • Fixed 'wrong number of arguments' errors when running on JRuby 9.0. #114.
    • Fixed warnings when running on Ruby 2.8. #112.

    TZInfo v1.2.7 on RubyGems.org

    v1.2.6

    • Timezone#strftime('%s', time) will now return the correct number of seconds since the epoch. #91.
    • Removed the unused TZInfo::RubyDataSource::REQUIRE_PATH constant.
    • Fixed "SecurityError: Insecure operation - require" exceptions when loading data with recent Ruby releases in safe mode.
    • Fixed warnings when running on Ruby 2.7. #106 and #111.

    TZInfo v1.2.6 on RubyGems.org

    Changelog

    Sourced from tzinfo's changelog.

    Version 1.2.10 - 19-Jul-2022

    Version 1.2.9 - 16-Dec-2020

    • Fixed an incorrect InvalidTimezoneIdentifier exception raised when loading a zoneinfo file that includes rules specifying an additional transition to the final defined offset (for example, Africa/Casablanca in version 2018e of the Time Zone Database). #123.

    Version 1.2.8 - 8-Nov-2020

    • Added support for handling "slim" format zoneinfo files that are produced by default by zic version 2020b and later. The POSIX-style TZ string is now used calculate DST transition times after the final defined transition in the file. The 64-bit section is now always used regardless of whether Time has support for 64-bit times. #120.
    • Rubinius is no longer supported.

    Version 1.2.7 - 2-Apr-2020

    • Fixed 'wrong number of arguments' errors when running on JRuby 9.0. #114.
    • Fixed warnings when running on Ruby 2.8. #112.

    Version 1.2.6 - 24-Dec-2019

    • Timezone#strftime('%s', time) will now return the correct number of seconds since the epoch. #91.
    • Removed the unused TZInfo::RubyDataSource::REQUIRE_PATH constant.
    • Fixed "SecurityError: Insecure operation - require" exceptions when loading data with recent Ruby releases in safe mode.
    • Fixed warnings when running on Ruby 2.7. #106 and #111.
    Commits
    • 0814dcd Fix the release date.
    • fd05e2a Preparing v1.2.10.
    • b98c32e Merge branch 'fix-directory-traversal-1.2' into 1.2
    • ac3ee68 Remove unnecessary escaping of + within regex character classes.
    • 9d49bf9 Fix relative path loading tests.
    • 394c381 Remove private_constant for consistency and compatibility.
    • 5e9f990 Exclude Arch Linux's SECURITY file from the time zone index.
    • 17fc9e1 Workaround for 'Permission denied - NUL' errors with JRuby on Windows.
    • 6bd7a51 Update copyright years.
    • 9905ca9 Fix directory traversal in Timezone.get when using Ruby data source
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
Releases(1.4.1)
  • 1.4.1(Apr 18, 2022)

  • 1.4.0(Oct 22, 2020)

  • 1.3.0(Feb 18, 2020)

    Support for building with Xcode 11 and Swift 5.0. This version requires Xcode 11 or later with Swift 5.0 compiler (#33) via David Cordero

    Source code(tar.gz)
    Source code(zip)
  • 1.2.3(Jan 16, 2019)

    This release adds new functionality, focusableMode to define when the button should be focused (#29).

    By default, the focusable mode is set to auto. When the text is too long the button will be focusable, else it will not be focusable. This is the current behavior.

    In addition, you can set the focusable mode to manual(_ isFocusable: Bool). This mode will force the button to be always be focused or never be focused.

    • Added focusableMode property (#29) via Roman Gritsuk

    Personal thanks to everyone who contributed! ๐Ÿ™‡

    Let make 2019 a great year together! ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

    Source code(tar.gz)
    Source code(zip)
  • 1.2.2(Dec 18, 2018)

    This release fixes a bug (#26) where the trailing text was being truncated.

    • Fixes a bug where the trailing text is being truncated (#28) via Roman Gritsuk

    Personal thanks to everyone who contributed! ๐Ÿ™‡

    2019 is right around the corner! ๐Ÿ˜‰ ๐ŸŽ†

    Source code(tar.gz)
    Source code(zip)
  • 1.2.1(Dec 6, 2018)

    This release fixes a bug (#24) where the button (un)focused style is not correct.

    • Fixes a bug where the button (un)focused style is not correct (#25) via Chris Goldsby

    No API changes.

    Have a great winter everyone! Stay warm! And, if I don't see you, "Have a great New Year!" โ›„๏ธ

    Source code(tar.gz)
    Source code(zip)
  • 1.2.0(Oct 14, 2018)

    Support for building with Xcode 10 and Swift 4.2. This version requires Xcode 10 or later with Swift 4.2 compiler.

    No API changes.

    Have a great week everybody! ๐ŸŽธ

    Source code(tar.gz)
    Source code(zip)
  • 1.1.4(Sep 26, 2018)

    Added textAlignment property to improve right to left text support, e.g. Arabic language.

    • Added textAlignment (#18) via Furkan Hatipoglu

    Personal thanks to everyone who contributed! ๐Ÿ™‡

    Almost October; may your Halloween be spooky! ๐ŸŽƒ

    Source code(tar.gz)
    Source code(zip)
  • 1.1.3(Sep 1, 2018)

  • 1.1.2(May 26, 2018)

    No API changes.

    • Add UIAccessibility (#14) via Chris Goldsby
    • Code style updates (#13) via Chris Goldsby

    Have a Happy Spring everyone! ๐ŸŒป

    Source code(tar.gz)
    Source code(zip)
  • 1.1.1(Oct 26, 2017)

    No API changes.

    • Document installation via Carthage (#8) via David Cordero
    • Objective-C Support (#9) via Andrรฉ Silva
    • Fix "characters was deprecated" warning (#10) via David Cordero

    What a great release! Personal thanks to everyone who contributed! ๐Ÿ™‡

    Have a Happy Fall everyone! ๐Ÿ‚

    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(Sep 12, 2017)

    Xcode 9 and 3.2+ is now required.

    Changes This library has been migrated to Swift 4.

    No API changes.

    Swift 3.2 Support

    If your project is using Swift 3.2, you can still use this release by overriding the SWIFT_VERSION to be 4.0 in your Podfile.

    post_install do |installer|
        installer.pods_project.targets.each do |target|
            if target.name == 'TvOSMoreButton'
                target.build_configurations.each do |config|
                    config.build_settings['SWIFT_VERSION'] = '4.0'
                end
            end
        end
    end
    

    Or, you can use the previous release, 1.0.2, which does not require the post_install hook and will compile just fine with Xcode 9 and Swift 3.2.

    ๐ŸŽ‰

    Source code(tar.gz)
    Source code(zip)
  • 1.0.2(Apr 23, 2017)

    No API changes.

    Added

    The TvOSMoreButton is now localized in:

    Espaรฑol Mexicano ๐Ÿ‡ฒ๐Ÿ‡ฝ
    Japanese ๐Ÿ‡ฏ๐Ÿ‡ต
    Dutch ๐Ÿ‡ณ๐Ÿ‡ฑ
    Norwegian ๐Ÿ‡ณ๐Ÿ‡ด Russian ๐Ÿ‡ท๐Ÿ‡บ

    ๐ŸŒ ๐ŸŽ‰

    Source code(tar.gz)
    Source code(zip)
  • 1.0.1(Mar 25, 2017)

    No API changes.

    Added

    The TvOSMoreButton is now localized in:

    Espaรฑol ๐Ÿ‡ฉ๐Ÿ‡ช French ๐Ÿ‡ซ๐Ÿ‡ท Deutsch ๐Ÿ‡ช๐Ÿ‡ธ Italian ๐Ÿ‡ฎ๐Ÿ‡น

    ๐ŸŒ ๐ŸŽ‰

    Source code(tar.gz)
    Source code(zip)
A simple library to make authenticating tvOS apps easy via their iOS counterparts.

Voucher The new Apple TV is amazing but the keyboard input leaves a lot to be desired. Instead of making your users type credentials into their TV, yo

Riz 516 Nov 24, 2022
YouTube video player for iOS, tvOS and macOS

About XCDYouTubeKit is a YouTube video player for iOS, tvOS and macOS. Are you enjoying XCDYouTubeKit? You can say thank you with a tweet. I am also a

Cรฉdric Luthi 2.9k Dec 21, 2022
Google Analytics tracker for Apple tvOS provides an easy integration of Google Analyticsโ€™ measurement protocol for Apple TV.

Google Analytics tracker for Apple tvOS by Adswerve About Google Analytics tracker for Apple tvOS provides an easy integration of Google Analyticsโ€™ me

Adswerve 81 Nov 13, 2022
tvOS controls and extensions that add parallax effect to your application.

ParallaxView Summary Easy to use UIView, UICollectionViewCell with parallax effect and extensions to add this effect to any UIView. Rotate view using

PGS Software 466 Nov 13, 2022
Light wrapper of UIButton that allows extra customization for tvOS

FocusTvButton Light wrapper of UIButton that allows extra customization for tvOS If you would like to have the same level of customization in tablevie

David Cordero 68 Nov 12, 2022
PIN keyboard for tvOS

TvOSPinKeyboard PIN keyboard for tvOS Description TvOSPinKeyboard is a view controller that allows easily asking for PIN codes in tvOS. Requirements t

Zattoo 102 Oct 5, 2022
Light wrapper of UITableViewCell that allows extra customization for tvOS

TvOSCustomizableTableViewCell Light wrapper of UITableViewCell that allows extra customization for tvOS If you would like to have the same level of cu

Zattoo 31 Nov 9, 2022
TvOSSlider is an implementation of UISlider for tvOS.

TvOSSlider TvOSSlider is an implementation of UISlider for tvOS. Description and usage TvOSSlider palliates missing an implementation of UISlider for

Zattoo 36 Dec 12, 2022
Reproduction for long-press, drag & hold bug in XCUITest API.

XCUITest Bug Reproduction press(forDuration:thenDragTo:withVelocity:thenHoldForDuration:) Reproduction for long-press, drag & hold bug in XCUITest API

Asaf Korem 2 May 16, 2022
zekunyan 608 Dec 30, 2022
Custom UIView class that hosts an array of UIbuttons that have an 'underline' UIView beneath them which moves from button to button when the user presses on them.

Swift-Underlined-Button-Bar Custom UIView class that hosts an array of UIbuttons that have an 'underline' UIView beneath them which moves from button

Justin Cook 3 Aug 4, 2022
ExpandableText ๐Ÿ˜Ž (SwiftUI) Expand the text with the "more" button

ExpandableText ?? (SwiftUI) Expand the text with the "more" button Get Started import SwiftUI import ExpandableText struct ExpandableText_Test: View

null 35 Dec 26, 2022
The app allows the user to change text color and text content when the displayed button is clicked

Hello World! App Description This application allows the user to change text color and text content when the displayed button is clicked. App Walk-tho

null 0 Mar 15, 2022
Customizable download button with progress and transition animations. It is based on Apple's App Store download button.

AHDownloadButton is a customizable download button similar to the download button in the latest version of Apple's App Store app (since iOS 11). It fe

Amer Hukiฤ‡ 465 Dec 24, 2022
Revamped Download Button. It's kinda a reverse engineering of Netflix's app download button.

NFDownloadButton Revamped Download Button Requirements Installation Usage License Requirements iOS 8.0+ Swift 4.2+ Xcode 10.0+ Installation CocoaPods

Leonardo Cardoso 433 Nov 15, 2022
MUDownloadButton - a Progressive Download button written in pure swift and inspired by AppStore download button

MUDownloadButton is a Progressive Download button written in pure swift and inspired by AppStore download button . feel free to contribute and pull requests

Mohammad ShahibZadeh 2 Feb 20, 2022
Hamburger Menu Button - A hamburger menu button with full customization

Hamburger Menu Button A hamburger menu button with full customization. Inspired by VinhLe's idea on the Dribble How to use it You can config the looks

Toan Nguyen 114 Jun 12, 2022
Bar Button Item that can be moved anywhere in the screen, like Android's stickers button.

FlowBarButtonItem Bar Button Item that can be moved anywhere in the screen, like Android's stickers button. [![CI Status](http://img.shields.io/travis

noppefoxwolf 153 Sep 15, 2022
A SwiftUI button that expands to reveal more content.

CUIExpandableButton A SwiftUI button that expands to reveal more content. CUIExpandableButton is part of the Crystal UI framework (under developement)

Robert Cole 6 Dec 10, 2022
Changes the color of the label text when the button is pressed and also prints hello to the console

MY FIRST APP App Description This app changes the color of the label text when the button is pressed and also prints "hello" to the console. App Walk-

null 0 Nov 29, 2021