├── .gitignore ├── .swift-version ├── LICENSE ├── README.md ├── TVOSPicker.podspec ├── TVOSPicker.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── Cem.xcuserdatad │ └── xcschemes │ ├── TVOSPicker.xcscheme │ └── xcschememanagement.plist ├── TVOSPicker ├── AppDelegate.swift ├── Assets.xcassets │ ├── App Icon & Top Shelf Image.brandassets │ │ ├── App Icon - Large.imagestack │ │ │ ├── Back.imagestacklayer │ │ │ │ ├── Content.imageset │ │ │ │ │ └── Contents.json │ │ │ │ └── Contents.json │ │ │ ├── Contents.json │ │ │ ├── Front.imagestacklayer │ │ │ │ ├── Content.imageset │ │ │ │ │ └── Contents.json │ │ │ │ └── Contents.json │ │ │ └── Middle.imagestacklayer │ │ │ │ ├── Content.imageset │ │ │ │ └── Contents.json │ │ │ │ └── Contents.json │ │ ├── App Icon - Small.imagestack │ │ │ ├── Back.imagestacklayer │ │ │ │ ├── Content.imageset │ │ │ │ │ └── Contents.json │ │ │ │ └── Contents.json │ │ │ ├── Contents.json │ │ │ ├── Front.imagestacklayer │ │ │ │ ├── Content.imageset │ │ │ │ │ └── Contents.json │ │ │ │ └── Contents.json │ │ │ └── Middle.imagestacklayer │ │ │ │ ├── Content.imageset │ │ │ │ └── Contents.json │ │ │ │ └── Contents.json │ │ ├── Contents.json │ │ ├── Top Shelf Image Wide.imageset │ │ │ └── Contents.json │ │ └── Top Shelf Image.imageset │ │ │ └── Contents.json │ ├── Contents.json │ └── LaunchImage.launchimage │ │ └── Contents.json ├── Base.lproj │ └── Main.storyboard ├── Info.plist ├── TVOSPickerViewController.swift └── ViewController.swift └── demo.gif /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/swift,xcode 3 | 4 | ### Swift ### 5 | # Xcode 6 | # 7 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 8 | 9 | ## Build generated 10 | build/ 11 | DerivedData/ 12 | 13 | ## Various settings 14 | *.pbxuser 15 | !default.pbxuser 16 | *.mode1v3 17 | !default.mode1v3 18 | *.mode2v3 19 | !default.mode2v3 20 | *.perspectivev3 21 | !default.perspectivev3 22 | xcuserdata/ 23 | 24 | ## Other 25 | *.moved-aside 26 | *.xcuserstate 27 | 28 | ## Obj-C/Swift specific 29 | *.hmap 30 | *.ipa 31 | *.dSYM.zip 32 | *.dSYM 33 | 34 | ## Playgrounds 35 | timeline.xctimeline 36 | playground.xcworkspace 37 | 38 | # Swift Package Manager 39 | # 40 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 41 | # Packages/ 42 | .build/ 43 | 44 | # CocoaPods 45 | # 46 | # We recommend against adding the Pods directory to your .gitignore. However 47 | # you should judge for yourself, the pros and cons are mentioned at: 48 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 49 | # 50 | Pods/ 51 | 52 | # Carthage 53 | # 54 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 55 | Carthage/Checkouts 56 | 57 | Carthage/Build 58 | 59 | # fastlane 60 | # 61 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 62 | # screenshots whenever they are needed. 63 | # For more information about the recommended setup visit: 64 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 65 | 66 | fastlane/report.xml 67 | fastlane/Preview.html 68 | fastlane/screenshots 69 | fastlane/test_output 70 | 71 | 72 | ### Xcode ### 73 | # Xcode 74 | # 75 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 76 | 77 | ## Build generated 78 | 79 | ## Various settings 80 | 81 | ## Other 82 | *.xccheckout 83 | *.xcscmblueprint 84 | 85 | # Docs 86 | docs/ 87 | 88 | # End of https://www.gitignore.io/api/swift,xcode 89 | -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 4.0 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2017, Cem Olcay 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a 4 | copy of this software and associated documentation files (the "Software"), 5 | to deal in the Software without restriction, including without limitation 6 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | and/or sell copies of the Software, and to permit persons to whom the 8 | Software is furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | DEALINGS IN THE SOFTWARE. 20 | 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | TVOSPicker 2 | === 3 | 4 | A sweet horizontal picker view controller for tvOS. 5 | 6 | Demo 7 | ---- 8 | 9 | ![alt tag](https://github.com/cemolcay/TVOSPicker/blob/master/demo.gif?raw=true) 10 | 11 | Requirements 12 | ---- 13 | 14 | - Swift 4.0+ 15 | - tvOS 9.0+ 16 | 17 | Install 18 | ---- 19 | 20 | ``` 21 | # in your tvOS target 22 | use_frameworks! 23 | pod 'TVOSPicker' 24 | ``` 25 | 26 | Usage 27 | ---- 28 | 29 | There are two ways to use this library. 30 | - First one is with traditional ways, create either programmatically or from storyboard, a `TVOSPickerViewController` instance and implement its delegate methods, set `dataSource`, `titleLabel` and `subtitleLabel` texts. 31 | - Other one is call `presentPicker(title:subtitle:dataSource:initialSelection:onSelectItem)` on your presenting view controller. 32 | - If your view controller has a navigation controller, than `TVOSPickerViewController` would be pushed by navigation controller and pop after a cancellation or a selection. 33 | - Otherwise, it would be presented modally over the presenting view controller. So, you should be careful when you call it over an already modally presented view controller. I recommend you to wrap it with a navigation controller if you tend to present a picker from a modally presented view controller. -------------------------------------------------------------------------------- /TVOSPicker.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod spec lint TVOSPicker.podspec' to ensure this is a 3 | # valid spec and to remove all comments including this before submitting the spec. 4 | # 5 | # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html 6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | 11 | # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 12 | # 13 | # These will help people to find your library, and whilst it 14 | # can feel like a chore to fill in it's definitely to your advantage. The 15 | # summary should be tweet-length, and the description more in depth. 16 | # 17 | 18 | s.name = "TVOSPicker" 19 | s.version = "0.0.2" 20 | s.summary = "A sweet horizontal picker view controller for tvOS." 21 | 22 | # This description is used to generate tags and improve search results. 23 | # * Think: What does it do? Why did you write it? What is the focus? 24 | # * Try to keep it short, snappy and to the point. 25 | # * Write the description between the DESC delimiters below. 26 | # * Finally, don't worry about the indent, CocoaPods strips it! 27 | s.description = <<-DESC 28 | TVOSPicker 29 | === 30 | 31 | A sweet horizontal picker view controller for tvOS. 32 | 33 | Demo 34 | ---- 35 | 36 | ![alt tag](https://github.com/cemolcay/TVOSPicker/blob/master/demo.gif?raw=true) 37 | 38 | Requirements 39 | ---- 40 | 41 | - Swift 3.0+ 42 | - tvOS 9.0+ 43 | 44 | Install 45 | ---- 46 | 47 | ``` 48 | # in your tvOS target 49 | use_frameworks! 50 | pod 'TVOSPicker' 51 | ``` 52 | 53 | Usage 54 | ---- 55 | 56 | There are two ways to use this library. 57 | - First one is with traditional ways, create either programmatically or from storyboard, a `TVOSPickerViewController` instance and implement its delegate methods, set `dataSource`, `titleLabel` and `subtitleLabel` texts. 58 | - Other one is call `presentPicker(title:subtitle:dataSource:initialSelection:onSelectItem)` on your presenting view controller. 59 | - If your view controller has a navigation controller, than `TVOSPickerViewController` would be pushed by navigation controller and pop after a cancellation or a selection. 60 | - Otherwise, it would be presented modally over the presenting view controller. So, you should be careful when you call it over an already modally presented view controller. I recommend you to wrap it with a navigation controller if you tend to present a picker from a modally presented view controller. 61 | DESC 62 | 63 | s.homepage = "https://github.com/cemolcay/TVOSPicker" 64 | # s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif" 65 | 66 | 67 | # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 68 | # 69 | # Licensing your code is important. See http://choosealicense.com for more info. 70 | # CocoaPods will detect a license file if there is a named LICENSE* 71 | # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'. 72 | # 73 | 74 | s.license = "MIT" 75 | # s.license = { :type => "MIT", :file => "FILE_LICENSE" } 76 | 77 | 78 | # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 79 | # 80 | # Specify the authors of the library, with email addresses. Email addresses 81 | # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also 82 | # accepts just a name if you'd rather not provide an email address. 83 | # 84 | # Specify a social_media_url where others can refer to, for example a twitter 85 | # profile URL. 86 | # 87 | 88 | s.author = { "cemolcay" => "ccemolcay@gmail.com" } 89 | # Or just: s.author = "cemolcay" 90 | # s.authors = { "cemolcay" => "ccemolcay@gmail.com" } 91 | s.social_media_url = "http://twitter.com/cemolcay" 92 | 93 | # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 94 | # 95 | # If this Pod runs only on iOS or OS X, then specify the platform and 96 | # the deployment target. You can optionally include the target after the platform. 97 | # 98 | 99 | # s.platform = :ios 100 | s.platform = :tvos, "9.0" 101 | 102 | # When using multiple platforms 103 | # s.ios.deployment_target = "5.0" 104 | # s.osx.deployment_target = "10.7" 105 | # s.watchos.deployment_target = "2.0" 106 | # s.tvos.deployment_target = "9.0" 107 | 108 | 109 | # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 110 | # 111 | # Specify the location from where the source should be retrieved. 112 | # Supports git, hg, bzr, svn and HTTP. 113 | # 114 | 115 | s.source = { :git => "https://github.com/cemolcay/TVOSPicker.git", :tag => "#{s.version}" } 116 | 117 | 118 | # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 119 | # 120 | # CocoaPods is smart about how it includes source code. For source files 121 | # giving a folder will include any swift, h, m, mm, c & cpp files. 122 | # For header files it will include any header in the folder. 123 | # Not including the public_header_files will make all headers public. 124 | # 125 | 126 | s.source_files = "TVOSPicker/TVOSPickerViewController.swift" 127 | # s.exclude_files = "Classes/Exclude" 128 | 129 | # s.public_header_files = "Classes/**/*.h" 130 | 131 | 132 | # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 133 | # 134 | # A list of resources included with the Pod. These are copied into the 135 | # target bundle with a build phase script. Anything else will be cleaned. 136 | # You can preserve files from being cleaned, please don't preserve 137 | # non-essential files like tests, examples and documentation. 138 | # 139 | 140 | # s.resource = "icon.png" 141 | # s.resources = "Resources/*.png" 142 | 143 | # s.preserve_paths = "FilesToSave", "MoreFilesToSave" 144 | 145 | 146 | # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 147 | # 148 | # Link your library with frameworks, or libraries. Libraries do not include 149 | # the lib prefix of their name. 150 | # 151 | 152 | # s.framework = "SomeFramework" 153 | # s.frameworks = "SomeFramework", "AnotherFramework" 154 | 155 | # s.library = "iconv" 156 | # s.libraries = "iconv", "xml2" 157 | 158 | 159 | # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 160 | # 161 | # If your library depends on compiler flags you can set them in the xcconfig hash 162 | # where they will only apply to your library. If you depend on other Podspecs 163 | # you can include multiple dependencies to ensure it works. 164 | 165 | s.requires_arc = true 166 | 167 | # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" } 168 | # s.dependency "JSONKit", "~> 1.4" 169 | 170 | end 171 | -------------------------------------------------------------------------------- /TVOSPicker.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | B27E3EFE1EC0AB6A003E8189 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B27E3EFD1EC0AB6A003E8189 /* AppDelegate.swift */; }; 11 | B27E3F001EC0AB6A003E8189 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B27E3EFF1EC0AB6A003E8189 /* ViewController.swift */; }; 12 | B27E3F031EC0AB6A003E8189 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B27E3F011EC0AB6A003E8189 /* Main.storyboard */; }; 13 | B27E3F051EC0AB6A003E8189 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B27E3F041EC0AB6A003E8189 /* Assets.xcassets */; }; 14 | B27E3F0D1EC0AB83003E8189 /* TVOSPickerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B27E3F0C1EC0AB83003E8189 /* TVOSPickerViewController.swift */; }; 15 | /* End PBXBuildFile section */ 16 | 17 | /* Begin PBXFileReference section */ 18 | B27E3EFA1EC0AB6A003E8189 /* TVOSPicker.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TVOSPicker.app; sourceTree = BUILT_PRODUCTS_DIR; }; 19 | B27E3EFD1EC0AB6A003E8189 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 20 | B27E3EFF1EC0AB6A003E8189 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 21 | B27E3F021EC0AB6A003E8189 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 22 | B27E3F041EC0AB6A003E8189 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 23 | B27E3F061EC0AB6A003E8189 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 24 | B27E3F0C1EC0AB83003E8189 /* TVOSPickerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TVOSPickerViewController.swift; sourceTree = ""; }; 25 | /* End PBXFileReference section */ 26 | 27 | /* Begin PBXFrameworksBuildPhase section */ 28 | B27E3EF71EC0AB6A003E8189 /* Frameworks */ = { 29 | isa = PBXFrameworksBuildPhase; 30 | buildActionMask = 2147483647; 31 | files = ( 32 | ); 33 | runOnlyForDeploymentPostprocessing = 0; 34 | }; 35 | /* End PBXFrameworksBuildPhase section */ 36 | 37 | /* Begin PBXGroup section */ 38 | B27E3EF11EC0AB6A003E8189 = { 39 | isa = PBXGroup; 40 | children = ( 41 | B27E3EFC1EC0AB6A003E8189 /* TVOSPicker */, 42 | B27E3EFB1EC0AB6A003E8189 /* Products */, 43 | ); 44 | sourceTree = ""; 45 | }; 46 | B27E3EFB1EC0AB6A003E8189 /* Products */ = { 47 | isa = PBXGroup; 48 | children = ( 49 | B27E3EFA1EC0AB6A003E8189 /* TVOSPicker.app */, 50 | ); 51 | name = Products; 52 | sourceTree = ""; 53 | }; 54 | B27E3EFC1EC0AB6A003E8189 /* TVOSPicker */ = { 55 | isa = PBXGroup; 56 | children = ( 57 | B27E3EFD1EC0AB6A003E8189 /* AppDelegate.swift */, 58 | B27E3EFF1EC0AB6A003E8189 /* ViewController.swift */, 59 | B27E3F0C1EC0AB83003E8189 /* TVOSPickerViewController.swift */, 60 | B27E3F011EC0AB6A003E8189 /* Main.storyboard */, 61 | B27E3F041EC0AB6A003E8189 /* Assets.xcassets */, 62 | B27E3F061EC0AB6A003E8189 /* Info.plist */, 63 | ); 64 | path = TVOSPicker; 65 | sourceTree = ""; 66 | }; 67 | /* End PBXGroup section */ 68 | 69 | /* Begin PBXNativeTarget section */ 70 | B27E3EF91EC0AB6A003E8189 /* TVOSPicker */ = { 71 | isa = PBXNativeTarget; 72 | buildConfigurationList = B27E3F091EC0AB6A003E8189 /* Build configuration list for PBXNativeTarget "TVOSPicker" */; 73 | buildPhases = ( 74 | B27E3EF61EC0AB6A003E8189 /* Sources */, 75 | B27E3EF71EC0AB6A003E8189 /* Frameworks */, 76 | B27E3EF81EC0AB6A003E8189 /* Resources */, 77 | ); 78 | buildRules = ( 79 | ); 80 | dependencies = ( 81 | ); 82 | name = TVOSPicker; 83 | productName = TVOSPicker; 84 | productReference = B27E3EFA1EC0AB6A003E8189 /* TVOSPicker.app */; 85 | productType = "com.apple.product-type.application"; 86 | }; 87 | /* End PBXNativeTarget section */ 88 | 89 | /* Begin PBXProject section */ 90 | B27E3EF21EC0AB6A003E8189 /* Project object */ = { 91 | isa = PBXProject; 92 | attributes = { 93 | LastSwiftUpdateCheck = 0830; 94 | LastUpgradeCheck = 1010; 95 | ORGANIZATIONNAME = cemolcay; 96 | TargetAttributes = { 97 | B27E3EF91EC0AB6A003E8189 = { 98 | CreatedOnToolsVersion = 8.3.2; 99 | ProvisioningStyle = Automatic; 100 | }; 101 | }; 102 | }; 103 | buildConfigurationList = B27E3EF51EC0AB6A003E8189 /* Build configuration list for PBXProject "TVOSPicker" */; 104 | compatibilityVersion = "Xcode 3.2"; 105 | developmentRegion = English; 106 | hasScannedForEncodings = 0; 107 | knownRegions = ( 108 | en, 109 | Base, 110 | ); 111 | mainGroup = B27E3EF11EC0AB6A003E8189; 112 | productRefGroup = B27E3EFB1EC0AB6A003E8189 /* Products */; 113 | projectDirPath = ""; 114 | projectRoot = ""; 115 | targets = ( 116 | B27E3EF91EC0AB6A003E8189 /* TVOSPicker */, 117 | ); 118 | }; 119 | /* End PBXProject section */ 120 | 121 | /* Begin PBXResourcesBuildPhase section */ 122 | B27E3EF81EC0AB6A003E8189 /* Resources */ = { 123 | isa = PBXResourcesBuildPhase; 124 | buildActionMask = 2147483647; 125 | files = ( 126 | B27E3F051EC0AB6A003E8189 /* Assets.xcassets in Resources */, 127 | B27E3F031EC0AB6A003E8189 /* Main.storyboard in Resources */, 128 | ); 129 | runOnlyForDeploymentPostprocessing = 0; 130 | }; 131 | /* End PBXResourcesBuildPhase section */ 132 | 133 | /* Begin PBXSourcesBuildPhase section */ 134 | B27E3EF61EC0AB6A003E8189 /* Sources */ = { 135 | isa = PBXSourcesBuildPhase; 136 | buildActionMask = 2147483647; 137 | files = ( 138 | B27E3F0D1EC0AB83003E8189 /* TVOSPickerViewController.swift in Sources */, 139 | B27E3F001EC0AB6A003E8189 /* ViewController.swift in Sources */, 140 | B27E3EFE1EC0AB6A003E8189 /* AppDelegate.swift in Sources */, 141 | ); 142 | runOnlyForDeploymentPostprocessing = 0; 143 | }; 144 | /* End PBXSourcesBuildPhase section */ 145 | 146 | /* Begin PBXVariantGroup section */ 147 | B27E3F011EC0AB6A003E8189 /* Main.storyboard */ = { 148 | isa = PBXVariantGroup; 149 | children = ( 150 | B27E3F021EC0AB6A003E8189 /* Base */, 151 | ); 152 | name = Main.storyboard; 153 | sourceTree = ""; 154 | }; 155 | /* End PBXVariantGroup section */ 156 | 157 | /* Begin XCBuildConfiguration section */ 158 | B27E3F071EC0AB6A003E8189 /* Debug */ = { 159 | isa = XCBuildConfiguration; 160 | buildSettings = { 161 | ALWAYS_SEARCH_USER_PATHS = NO; 162 | CLANG_ANALYZER_NONNULL = YES; 163 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 164 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 165 | CLANG_CXX_LIBRARY = "libc++"; 166 | CLANG_ENABLE_MODULES = YES; 167 | CLANG_ENABLE_OBJC_ARC = YES; 168 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 169 | CLANG_WARN_BOOL_CONVERSION = YES; 170 | CLANG_WARN_COMMA = YES; 171 | CLANG_WARN_CONSTANT_CONVERSION = YES; 172 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 173 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 174 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 175 | CLANG_WARN_EMPTY_BODY = YES; 176 | CLANG_WARN_ENUM_CONVERSION = YES; 177 | CLANG_WARN_INFINITE_RECURSION = YES; 178 | CLANG_WARN_INT_CONVERSION = YES; 179 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 180 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 181 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 182 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 183 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 184 | CLANG_WARN_STRICT_PROTOTYPES = YES; 185 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 186 | CLANG_WARN_UNREACHABLE_CODE = YES; 187 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 188 | CODE_SIGN_IDENTITY = ""; 189 | COPY_PHASE_STRIP = NO; 190 | DEBUG_INFORMATION_FORMAT = dwarf; 191 | ENABLE_STRICT_OBJC_MSGSEND = YES; 192 | ENABLE_TESTABILITY = YES; 193 | GCC_C_LANGUAGE_STANDARD = gnu99; 194 | GCC_DYNAMIC_NO_PIC = NO; 195 | GCC_NO_COMMON_BLOCKS = YES; 196 | GCC_OPTIMIZATION_LEVEL = 0; 197 | GCC_PREPROCESSOR_DEFINITIONS = ( 198 | "DEBUG=1", 199 | "$(inherited)", 200 | ); 201 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 202 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 203 | GCC_WARN_UNDECLARED_SELECTOR = YES; 204 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 205 | GCC_WARN_UNUSED_FUNCTION = YES; 206 | GCC_WARN_UNUSED_VARIABLE = YES; 207 | MTL_ENABLE_DEBUG_INFO = YES; 208 | ONLY_ACTIVE_ARCH = YES; 209 | SDKROOT = appletvos; 210 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 211 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 212 | SWIFT_VERSION = 4.0; 213 | TARGETED_DEVICE_FAMILY = 3; 214 | TVOS_DEPLOYMENT_TARGET = 10.2; 215 | }; 216 | name = Debug; 217 | }; 218 | B27E3F081EC0AB6A003E8189 /* Release */ = { 219 | isa = XCBuildConfiguration; 220 | buildSettings = { 221 | ALWAYS_SEARCH_USER_PATHS = NO; 222 | CLANG_ANALYZER_NONNULL = YES; 223 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 224 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 225 | CLANG_CXX_LIBRARY = "libc++"; 226 | CLANG_ENABLE_MODULES = YES; 227 | CLANG_ENABLE_OBJC_ARC = YES; 228 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 229 | CLANG_WARN_BOOL_CONVERSION = YES; 230 | CLANG_WARN_COMMA = YES; 231 | CLANG_WARN_CONSTANT_CONVERSION = YES; 232 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 233 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 234 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 235 | CLANG_WARN_EMPTY_BODY = YES; 236 | CLANG_WARN_ENUM_CONVERSION = YES; 237 | CLANG_WARN_INFINITE_RECURSION = YES; 238 | CLANG_WARN_INT_CONVERSION = YES; 239 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 240 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 241 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 242 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 243 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 244 | CLANG_WARN_STRICT_PROTOTYPES = YES; 245 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 246 | CLANG_WARN_UNREACHABLE_CODE = YES; 247 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 248 | CODE_SIGN_IDENTITY = ""; 249 | COPY_PHASE_STRIP = NO; 250 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 251 | ENABLE_NS_ASSERTIONS = NO; 252 | ENABLE_STRICT_OBJC_MSGSEND = YES; 253 | GCC_C_LANGUAGE_STANDARD = gnu99; 254 | GCC_NO_COMMON_BLOCKS = YES; 255 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 256 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 257 | GCC_WARN_UNDECLARED_SELECTOR = YES; 258 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 259 | GCC_WARN_UNUSED_FUNCTION = YES; 260 | GCC_WARN_UNUSED_VARIABLE = YES; 261 | MTL_ENABLE_DEBUG_INFO = NO; 262 | SDKROOT = appletvos; 263 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 264 | SWIFT_VERSION = 4.0; 265 | TARGETED_DEVICE_FAMILY = 3; 266 | TVOS_DEPLOYMENT_TARGET = 10.2; 267 | VALIDATE_PRODUCT = YES; 268 | }; 269 | name = Release; 270 | }; 271 | B27E3F0A1EC0AB6A003E8189 /* Debug */ = { 272 | isa = XCBuildConfiguration; 273 | buildSettings = { 274 | ASSETCATALOG_COMPILER_APPICON_NAME = "App Icon & Top Shelf Image"; 275 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 276 | DEVELOPMENT_TEAM = ""; 277 | INFOPLIST_FILE = TVOSPicker/Info.plist; 278 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 279 | PRODUCT_BUNDLE_IDENTIFIER = com.cemolcay.TVOSPicker; 280 | PRODUCT_NAME = "$(TARGET_NAME)"; 281 | SWIFT_VERSION = 4.2; 282 | TVOS_DEPLOYMENT_TARGET = 9.0; 283 | }; 284 | name = Debug; 285 | }; 286 | B27E3F0B1EC0AB6A003E8189 /* Release */ = { 287 | isa = XCBuildConfiguration; 288 | buildSettings = { 289 | ASSETCATALOG_COMPILER_APPICON_NAME = "App Icon & Top Shelf Image"; 290 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 291 | DEVELOPMENT_TEAM = ""; 292 | INFOPLIST_FILE = TVOSPicker/Info.plist; 293 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 294 | PRODUCT_BUNDLE_IDENTIFIER = com.cemolcay.TVOSPicker; 295 | PRODUCT_NAME = "$(TARGET_NAME)"; 296 | SWIFT_VERSION = 4.2; 297 | TVOS_DEPLOYMENT_TARGET = 9.0; 298 | }; 299 | name = Release; 300 | }; 301 | /* End XCBuildConfiguration section */ 302 | 303 | /* Begin XCConfigurationList section */ 304 | B27E3EF51EC0AB6A003E8189 /* Build configuration list for PBXProject "TVOSPicker" */ = { 305 | isa = XCConfigurationList; 306 | buildConfigurations = ( 307 | B27E3F071EC0AB6A003E8189 /* Debug */, 308 | B27E3F081EC0AB6A003E8189 /* Release */, 309 | ); 310 | defaultConfigurationIsVisible = 0; 311 | defaultConfigurationName = Release; 312 | }; 313 | B27E3F091EC0AB6A003E8189 /* Build configuration list for PBXNativeTarget "TVOSPicker" */ = { 314 | isa = XCConfigurationList; 315 | buildConfigurations = ( 316 | B27E3F0A1EC0AB6A003E8189 /* Debug */, 317 | B27E3F0B1EC0AB6A003E8189 /* Release */, 318 | ); 319 | defaultConfigurationIsVisible = 0; 320 | defaultConfigurationName = Release; 321 | }; 322 | /* End XCConfigurationList section */ 323 | }; 324 | rootObject = B27E3EF21EC0AB6A003E8189 /* Project object */; 325 | } 326 | -------------------------------------------------------------------------------- /TVOSPicker.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TVOSPicker.xcodeproj/xcuserdata/Cem.xcuserdatad/xcschemes/TVOSPicker.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 33 | 34 | 40 | 41 | 42 | 43 | 44 | 45 | 56 | 58 | 64 | 65 | 66 | 67 | 68 | 69 | 75 | 77 | 83 | 84 | 85 | 86 | 88 | 89 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /TVOSPicker.xcodeproj/xcuserdata/Cem.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | TVOSPicker.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | B27E3EF91EC0AB6A003E8189 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /TVOSPicker/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // TVOSPicker 4 | // 5 | // Created by Cem Olcay on 08/05/2017. 6 | // Copyright © 2017 cemolcay. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /TVOSPicker/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Content.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "tv", 5 | "scale" : "1x" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /TVOSPicker/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /TVOSPicker/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "layers" : [ 3 | { 4 | "filename" : "Front.imagestacklayer" 5 | }, 6 | { 7 | "filename" : "Middle.imagestacklayer" 8 | }, 9 | { 10 | "filename" : "Back.imagestacklayer" 11 | } 12 | ], 13 | "info" : { 14 | "version" : 1, 15 | "author" : "xcode" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /TVOSPicker/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Content.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "tv", 5 | "scale" : "1x" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /TVOSPicker/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /TVOSPicker/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "tv", 5 | "scale" : "1x" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /TVOSPicker/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /TVOSPicker/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Content.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "tv", 5 | "scale" : "1x" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /TVOSPicker/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /TVOSPicker/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "layers" : [ 3 | { 4 | "filename" : "Front.imagestacklayer" 5 | }, 6 | { 7 | "filename" : "Middle.imagestacklayer" 8 | }, 9 | { 10 | "filename" : "Back.imagestacklayer" 11 | } 12 | ], 13 | "info" : { 14 | "version" : 1, 15 | "author" : "xcode" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /TVOSPicker/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Content.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "tv", 5 | "scale" : "1x" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /TVOSPicker/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /TVOSPicker/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "tv", 5 | "scale" : "1x" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /TVOSPicker/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /TVOSPicker/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "assets" : [ 3 | { 4 | "size" : "1280x768", 5 | "idiom" : "tv", 6 | "filename" : "App Icon - Large.imagestack", 7 | "role" : "primary-app-icon" 8 | }, 9 | { 10 | "size" : "400x240", 11 | "idiom" : "tv", 12 | "filename" : "App Icon - Small.imagestack", 13 | "role" : "primary-app-icon" 14 | }, 15 | { 16 | "size" : "2320x720", 17 | "idiom" : "tv", 18 | "filename" : "Top Shelf Image Wide.imageset", 19 | "role" : "top-shelf-image-wide" 20 | }, 21 | { 22 | "size" : "1920x720", 23 | "idiom" : "tv", 24 | "filename" : "Top Shelf Image.imageset", 25 | "role" : "top-shelf-image" 26 | } 27 | ], 28 | "info" : { 29 | "version" : 1, 30 | "author" : "xcode" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /TVOSPicker/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image Wide.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "tv", 5 | "scale" : "1x" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /TVOSPicker/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "tv", 5 | "scale" : "1x" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /TVOSPicker/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /TVOSPicker/Assets.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "landscape", 5 | "idiom" : "tv", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "9.0", 8 | "scale" : "1x" 9 | } 10 | ], 11 | "info" : { 12 | "version" : 1, 13 | "author" : "xcode" 14 | } 15 | } -------------------------------------------------------------------------------- /TVOSPicker/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /TVOSPicker/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIMainStoryboardFile 24 | Main 25 | UIRequiredDeviceCapabilities 26 | 27 | arm64 28 | 29 | UIUserInterfaceStyle 30 | Automatic 31 | 32 | 33 | -------------------------------------------------------------------------------- /TVOSPicker/TVOSPickerViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TVOSPickerViewController.swift 3 | // TVOSPicker 4 | // 5 | // Created by Cem Olcay on 08/05/2017. 6 | // Copyright © 2017 cemolcay. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public class TVOSPickerCell: UICollectionViewCell { 12 | public static let cellReuseIdentifier = "PickerCell" 13 | public var titleLabel = UILabel() 14 | public var focusedScale: CGFloat = 1.2 15 | public var pressedScale: CGFloat = 0.9 16 | 17 | public override init(frame: CGRect) { 18 | super.init(frame: frame) 19 | commonInit() 20 | } 21 | 22 | public required init?(coder aDecoder: NSCoder) { 23 | super.init(coder: aDecoder) 24 | commonInit() 25 | } 26 | 27 | private func commonInit() { 28 | titleLabel.font = UIFont.preferredFont(forTextStyle: .body) 29 | titleLabel.textAlignment = .center 30 | titleLabel.textColor = .black 31 | titleLabel.translatesAutoresizingMaskIntoConstraints = false 32 | contentView.addSubview(titleLabel) 33 | NSLayoutConstraint.activate([ 34 | titleLabel.leftAnchor.constraint(equalTo: contentView.leftAnchor, constant: 0), 35 | titleLabel.rightAnchor.constraint(equalTo: contentView.rightAnchor, constant: 0), 36 | titleLabel.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 0), 37 | titleLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: 0) 38 | ]) 39 | } 40 | 41 | public override func prepareForReuse() { 42 | super.prepareForReuse() 43 | titleLabel.text = nil 44 | } 45 | 46 | public override func pressesBegan(_ presses: Set, with event: UIPressesEvent?) { 47 | super.pressesBegan(presses, with: event) 48 | spring(animations: { 49 | self.layer.transform = CATransform3DMakeScale(self.pressedScale, self.pressedScale, 1) 50 | }) 51 | } 52 | 53 | public override func pressesEnded(_ presses: Set, with event: UIPressesEvent?) { 54 | super.pressesEnded(presses, with: event) 55 | spring(animations: { 56 | self.layer.transform = CATransform3DMakeScale(self.focusedScale, self.focusedScale, 1) 57 | }) 58 | } 59 | 60 | public override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) { 61 | super.didUpdateFocus(in: context, with: coordinator) 62 | backgroundColor = isFocused ? .lightGray : .clear 63 | if self == context.nextFocusedView { 64 | coordinator.addCoordinatedAnimations({ 65 | self.layer.transform = CATransform3DMakeScale(self.focusedScale, self.focusedScale, 1) 66 | }, completion: nil) 67 | } else if self == context.previouslyFocusedView { 68 | coordinator.addCoordinatedAnimations({ 69 | self.layer.transform = CATransform3DIdentity 70 | }, completion: nil) 71 | } 72 | } 73 | 74 | private func spring(animations: @escaping () -> Void, completion: ((Bool) -> Void)? = nil) { 75 | UIView.animate( 76 | withDuration: 0.3, 77 | delay: 0, 78 | usingSpringWithDamping: 1, 79 | initialSpringVelocity: 0, 80 | options: .allowAnimatedContent, 81 | animations: animations, 82 | completion: completion) 83 | } 84 | } 85 | 86 | public protocol TVOSPickerViewControllerDelegate: class { 87 | func pickerViewController(_ pickerViewController: TVOSPickerViewController, didSelect item: String, at index: Int) 88 | func pickerViewControllerDidPressCancelButton(_ pickerViewController: TVOSPickerViewController) 89 | } 90 | 91 | public class TVOSPickerViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { 92 | public var titleLabel = UILabel() 93 | public var subtitleLabel = UILabel() 94 | public var collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()) 95 | public var cancelButton = UIButton(type: .system) 96 | 97 | public var dataSource: [String] = [] 98 | public var defaultSelectedItemIndex = 0 99 | private var contentStack = UIStackView() 100 | private let cancelFocusGuide = UIFocusGuide() 101 | 102 | public weak var delegate: TVOSPickerViewControllerDelegate? 103 | 104 | private lazy var contentWidth: CGFloat = { 105 | return Array(0.. collectionView.frame.size.width { 219 | collectionView.scrollToItem(at: indexPath, at: .centeredHorizontally, animated: true) 220 | } 221 | 222 | // Setup focus guide 223 | if context.nextFocusedView == cancelButton { 224 | cancelFocusGuide.preferredFocusedView = collectionView 225 | } else if context.nextFocusedView == collectionView { 226 | cancelFocusGuide.preferredFocusedView = cancelButton 227 | } 228 | } 229 | 230 | // MARK: UICollectionViewDataSource 231 | 232 | public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 233 | return dataSource.count 234 | } 235 | 236 | public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 237 | guard let cell = collectionView.dequeueReusableCell( 238 | withReuseIdentifier: TVOSPickerCell.cellReuseIdentifier, 239 | for: indexPath) as? TVOSPickerCell 240 | else { fatalError() } 241 | 242 | cell.titleLabel.text = dataSource[indexPath.row] 243 | cell.layer.cornerRadius = 10 244 | cell.layer.masksToBounds = true 245 | 246 | return cell 247 | } 248 | 249 | // MARK: UICollectionViewDelegate 250 | 251 | public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 252 | let item = dataSource[indexPath.item] 253 | delegate?.pickerViewController(self, didSelect: item, at: indexPath.item) 254 | } 255 | 256 | // MARK: UICollectionViewDelegateFlowLayout 257 | 258 | public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { 259 | let item = dataSource[indexPath.item] 260 | let itemWidth = NSAttributedString( 261 | string: item, 262 | attributes: [NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .body)] 263 | ).boundingRect( 264 | with: CGSize(width: .max, height: .max), 265 | options: .usesDeviceMetrics, 266 | context: nil) 267 | .width 268 | return CGSize(width: itemWidth + 80, height: collectionView.frame.size.height - 40) 269 | } 270 | 271 | public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets { 272 | if contentWidth > collectionView.frame.size.width { 273 | return .zero 274 | } 275 | 276 | let padding = (collectionView.frame.size.width - contentWidth) / 2 277 | return UIEdgeInsets(top: 0, left: padding, bottom: 0, right: 0) 278 | } 279 | } 280 | 281 | public typealias TVOSPickerHandler = (_ item: String, _ at: Int) -> Void 282 | public var TVOSPickerHandlerAssociatedObject: UInt8 = 0 283 | extension UIViewController: TVOSPickerViewControllerDelegate { 284 | 285 | private var pickerHandler: TVOSPickerHandler? { 286 | get { 287 | return objc_getAssociatedObject(self, &TVOSPickerHandlerAssociatedObject) as? TVOSPickerHandler 288 | } set { 289 | objc_setAssociatedObject(self, &TVOSPickerHandlerAssociatedObject, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) 290 | } 291 | } 292 | 293 | public func pickerViewControllerDidPressCancelButton(_ pickerViewController: TVOSPickerViewController) { 294 | if let navigationController = navigationController { 295 | navigationController.popViewController(animated: true) 296 | } else { 297 | pickerViewController.dismiss(animated: true, completion: nil) 298 | } 299 | } 300 | 301 | public func pickerViewController(_ pickerViewController: TVOSPickerViewController, didSelect item: String, at index: Int) { 302 | pickerHandler?(item, index) 303 | pickerViewControllerDidPressCancelButton(pickerViewController) 304 | } 305 | 306 | public func presentPicker(title: String, subtitle: String? = nil, dataSource: [String], initialSelection: Int = 0, onSelectItem: @escaping TVOSPickerHandler) { 307 | let picker = TVOSPickerViewController() 308 | picker.titleLabel.text = title 309 | picker.subtitleLabel.text = subtitle 310 | picker.dataSource = dataSource 311 | picker.defaultSelectedItemIndex = initialSelection 312 | picker.delegate = self 313 | pickerHandler = onSelectItem 314 | if let navigationController = navigationController { 315 | navigationController.pushViewController(picker, animated: true) 316 | } else { 317 | present(picker, animated: true, completion: nil) 318 | } 319 | } 320 | } 321 | -------------------------------------------------------------------------------- /TVOSPicker/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // TVOSPicker 4 | // 5 | // Created by Cem Olcay on 08/05/2017. 6 | // Copyright © 2017 cemolcay. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | @IBAction func pickerButtonPressed(sender: UIButton) { 14 | var dataSource = Array(0..<10).map({ "Item \($0)" }) 15 | dataSource.insert("Some big item", at: 1) 16 | dataSource.insert("Some other big item", at: 4) 17 | 18 | presentPicker( 19 | title: "Example Picker", 20 | subtitle: "Some optional explanation message about what this picker picks", 21 | dataSource: dataSource, 22 | initialSelection: 0, 23 | onSelectItem: { item, index in 24 | print("\(item) selected at index \(index)") 25 | }) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cemolcay/TVOSPicker/3b6e51fe566332af29f19343a6eab85af0841b90/demo.gif --------------------------------------------------------------------------------