├── .gitignore ├── .swift-versions ├── 2018-07-24 09_48_10.gif ├── LICENSE ├── README.md ├── SwiftTTPageController.podspec ├── SwiftTTPageController.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ └── gener.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── gener.xcuserdatad │ └── xcschemes │ ├── SwiftTTPageController.xcscheme │ └── xcschememanagement.plist └── SwiftTTPageController ├── AppDelegate.swift ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── Info.plist ├── SwiftTTPageController ├── TTHeadView.swift └── TTPageViewController.swift ├── TableViewController.swift └── ViewController.swift /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | .DS_Store 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | *.xcuserstate 25 | 26 | ## Obj-C/Swift specific 27 | *.hmap 28 | *.ipa 29 | *.dSYM.zip 30 | *.dSYM 31 | 32 | ## Playgrounds 33 | timeline.xctimeline 34 | playground.xcworkspace 35 | 36 | # Swift Package Manager 37 | # 38 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 39 | # Packages/ 40 | # Package.pins 41 | .build/ 42 | 43 | # CocoaPods 44 | # 45 | # We recommend against adding the Pods directory to your .gitignore. However 46 | # you should judge for yourself, the pros and cons are mentioned at: 47 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 48 | # 49 | Pods/ 50 | 51 | # Carthage 52 | # 53 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 54 | # Carthage/Checkouts 55 | 56 | Carthage/Build 57 | 58 | # fastlane 59 | # 60 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 61 | # screenshots whenever they are needed. 62 | # For more information about the recommended setup visit: 63 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 64 | 65 | fastlane/report.xml 66 | fastlane/Preview.html 67 | fastlane/screenshots 68 | fastlane/test_output 69 | -------------------------------------------------------------------------------- /.swift-versions: -------------------------------------------------------------------------------- 1 | 5.0 2 | -------------------------------------------------------------------------------- /2018-07-24 09_48_10.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Light413/SwiftTTPageController/5d9f74b2ad2cbe41d82484c674c58d2705ecf90d/2018-07-24 09_48_10.gif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SwiftTTPageController 2 | > 仿网易新闻、头条等首页列表切换效果,实现多个ViewController列表切换; 3 | 4 | * Swift 5.0+ ,Xcode 11.4 5 | 6 | ## 效果如下: 7 | 8 | ![TTTagListController](https://github.com/Light413/DemoSwift_TTTagListController/blob/master/2018-07-24%2009_48_10.gif?raw=true) 9 | 10 | 11 | ## 安装 12 | 13 | ``` 14 | pod 'SwiftTTPageController' 15 | ``` 16 | 17 | ## 应用 18 | 19 | * 创建HeadView 20 | 21 | ``` 22 | let titles = ["新闻","视频","最新","新闻","视频","最新","军事","头条"] 23 | 24 | let headView = TTHeadView (frame: CGRect (x: 0, y: 0, width: UIScreen.main.bounds.width, height: 30), titles: titles, delegate: self) 25 | 26 | navigationItem.titleView = headView; 27 | 28 | ``` 29 | 30 | * 创建列表控制器,并添加到父控制器之上 31 | 32 | ``` 33 | let vcs = [TableViewController(),TableViewController(),TableViewController(),TableViewController(),TableViewController(),TableViewController(),TableViewController(),TableViewController(),] 34 | 35 | let frame = CGRect (x: 0, y: 0, width: view.frame.width, height: view.frame.height) 36 | 37 | let pagevc = TTPageViewController.init(controllers: vcs, frame: frame, delegate: self) 38 | 39 | self.addChildViewController(pagevc) 40 | self.view.addSubview(pagevc.view) 41 | 42 | ``` 43 | 44 | * 遵守协议`TTHeadViewDelegate,TTPageViewControllerDelegate ` 实现代理方法,处理事件 45 | 46 | ``` 47 | /////Delegate methods 48 | func tt_headViewSelectedAt(_ index: Int) { 49 | pagevc.scrollToPageAtIndex(index) 50 | } 51 | 52 | func tt_pageControllerSelectedAt(_ index: Int) { 53 | headView.scrollToItemAtIndex(index) 54 | } 55 | 56 | ``` 57 | 58 | ## License 59 | 60 | See LICENSE file for details 61 | 62 | -------------------------------------------------------------------------------- /SwiftTTPageController.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "SwiftTTPageController" 3 | s.version = "0.0.6" 4 | s.summary = "A useful PageController lib 仿今日头条首页、网易新闻首页 ,实现多个ViewController列表切换." 5 | s.description = <<-DESC 6 | A Simple PageController ,like Toutiao , NetEase Home.(仿今日头条首页、网易新闻首页 ,实现多个ViewController列表切换). 7 | DESC 8 | 9 | s.homepage = "https://github.com/Light413/SwiftTTPageController" 10 | s.license = "MIT" 11 | s.author = { "Light413" => "1289988413@qq.com" } 12 | 13 | #s.platform = :ios, "9.0" 14 | s.ios.deployment_target = '9.0' 15 | 16 | s.source = { :git => "https://github.com/Light413/SwiftTTPageController.git", :tag =>s.version } 17 | 18 | s.source_files = "SwiftTTPageController/SwiftTTPageController/*.swift" 19 | s.requires_arc = true 20 | s.framework = "UIKit","Foundation" 21 | end 22 | -------------------------------------------------------------------------------- /SwiftTTPageController.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | A12E70CC211AEB7D0016FA1E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A12E70CB211AEB7D0016FA1E /* AppDelegate.swift */; }; 11 | A12E70CE211AEB7D0016FA1E /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A12E70CD211AEB7D0016FA1E /* ViewController.swift */; }; 12 | A12E70D1211AEB7D0016FA1E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A12E70CF211AEB7D0016FA1E /* Main.storyboard */; }; 13 | A12E70D3211AEB7D0016FA1E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A12E70D2211AEB7D0016FA1E /* Assets.xcassets */; }; 14 | A12E70D6211AEB7D0016FA1E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A12E70D4211AEB7D0016FA1E /* LaunchScreen.storyboard */; }; 15 | A12E70DF211AECB70016FA1E /* TTHeadView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A12E70DE211AECB70016FA1E /* TTHeadView.swift */; }; 16 | A12E70E1211AECF70016FA1E /* TTPageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A12E70E0211AECF70016FA1E /* TTPageViewController.swift */; }; 17 | A12E70E3211AEE330016FA1E /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A12E70E2211AEE330016FA1E /* TableViewController.swift */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXFileReference section */ 21 | A12E70C8211AEB7D0016FA1E /* SwiftTTPageController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwiftTTPageController.app; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | A12E70CB211AEB7D0016FA1E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 23 | A12E70CD211AEB7D0016FA1E /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 24 | A12E70D0211AEB7D0016FA1E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 25 | A12E70D2211AEB7D0016FA1E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 26 | A12E70D5211AEB7D0016FA1E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 27 | A12E70D7211AEB7D0016FA1E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 28 | A12E70DE211AECB70016FA1E /* TTHeadView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TTHeadView.swift; sourceTree = ""; }; 29 | A12E70E0211AECF70016FA1E /* TTPageViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TTPageViewController.swift; sourceTree = ""; }; 30 | A12E70E2211AEE330016FA1E /* TableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = ""; }; 31 | /* End PBXFileReference section */ 32 | 33 | /* Begin PBXFrameworksBuildPhase section */ 34 | A12E70C5211AEB7D0016FA1E /* Frameworks */ = { 35 | isa = PBXFrameworksBuildPhase; 36 | buildActionMask = 2147483647; 37 | files = ( 38 | ); 39 | runOnlyForDeploymentPostprocessing = 0; 40 | }; 41 | /* End PBXFrameworksBuildPhase section */ 42 | 43 | /* Begin PBXGroup section */ 44 | A12E70BF211AEB7C0016FA1E = { 45 | isa = PBXGroup; 46 | children = ( 47 | A12E70CA211AEB7D0016FA1E /* SwiftTTPageController */, 48 | A12E70C9211AEB7D0016FA1E /* Products */, 49 | ); 50 | sourceTree = ""; 51 | }; 52 | A12E70C9211AEB7D0016FA1E /* Products */ = { 53 | isa = PBXGroup; 54 | children = ( 55 | A12E70C8211AEB7D0016FA1E /* SwiftTTPageController.app */, 56 | ); 57 | name = Products; 58 | sourceTree = ""; 59 | }; 60 | A12E70CA211AEB7D0016FA1E /* SwiftTTPageController */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | A12E70DD211AEBC30016FA1E /* SwiftTTPageController */, 64 | A12E70CB211AEB7D0016FA1E /* AppDelegate.swift */, 65 | A12E70E2211AEE330016FA1E /* TableViewController.swift */, 66 | A12E70CD211AEB7D0016FA1E /* ViewController.swift */, 67 | A12E70CF211AEB7D0016FA1E /* Main.storyboard */, 68 | A12E70D2211AEB7D0016FA1E /* Assets.xcassets */, 69 | A12E70D4211AEB7D0016FA1E /* LaunchScreen.storyboard */, 70 | A12E70D7211AEB7D0016FA1E /* Info.plist */, 71 | ); 72 | path = SwiftTTPageController; 73 | sourceTree = ""; 74 | }; 75 | A12E70DD211AEBC30016FA1E /* SwiftTTPageController */ = { 76 | isa = PBXGroup; 77 | children = ( 78 | A12E70DE211AECB70016FA1E /* TTHeadView.swift */, 79 | A12E70E0211AECF70016FA1E /* TTPageViewController.swift */, 80 | ); 81 | path = SwiftTTPageController; 82 | sourceTree = ""; 83 | }; 84 | /* End PBXGroup section */ 85 | 86 | /* Begin PBXNativeTarget section */ 87 | A12E70C7211AEB7D0016FA1E /* SwiftTTPageController */ = { 88 | isa = PBXNativeTarget; 89 | buildConfigurationList = A12E70DA211AEB7D0016FA1E /* Build configuration list for PBXNativeTarget "SwiftTTPageController" */; 90 | buildPhases = ( 91 | A12E70C4211AEB7D0016FA1E /* Sources */, 92 | A12E70C5211AEB7D0016FA1E /* Frameworks */, 93 | A12E70C6211AEB7D0016FA1E /* Resources */, 94 | ); 95 | buildRules = ( 96 | ); 97 | dependencies = ( 98 | ); 99 | name = SwiftTTPageController; 100 | productName = SwiftTTPageController; 101 | productReference = A12E70C8211AEB7D0016FA1E /* SwiftTTPageController.app */; 102 | productType = "com.apple.product-type.application"; 103 | }; 104 | /* End PBXNativeTarget section */ 105 | 106 | /* Begin PBXProject section */ 107 | A12E70C0211AEB7C0016FA1E /* Project object */ = { 108 | isa = PBXProject; 109 | attributes = { 110 | LastSwiftUpdateCheck = 0800; 111 | LastUpgradeCheck = 0800; 112 | ORGANIZATIONNAME = Light; 113 | TargetAttributes = { 114 | A12E70C7211AEB7D0016FA1E = { 115 | CreatedOnToolsVersion = 8.0; 116 | DevelopmentTeam = 8R29X3H9MY; 117 | LastSwiftMigration = 1140; 118 | ProvisioningStyle = Automatic; 119 | }; 120 | }; 121 | }; 122 | buildConfigurationList = A12E70C3211AEB7C0016FA1E /* Build configuration list for PBXProject "SwiftTTPageController" */; 123 | compatibilityVersion = "Xcode 3.2"; 124 | developmentRegion = English; 125 | hasScannedForEncodings = 0; 126 | knownRegions = ( 127 | English, 128 | en, 129 | Base, 130 | ); 131 | mainGroup = A12E70BF211AEB7C0016FA1E; 132 | productRefGroup = A12E70C9211AEB7D0016FA1E /* Products */; 133 | projectDirPath = ""; 134 | projectRoot = ""; 135 | targets = ( 136 | A12E70C7211AEB7D0016FA1E /* SwiftTTPageController */, 137 | ); 138 | }; 139 | /* End PBXProject section */ 140 | 141 | /* Begin PBXResourcesBuildPhase section */ 142 | A12E70C6211AEB7D0016FA1E /* Resources */ = { 143 | isa = PBXResourcesBuildPhase; 144 | buildActionMask = 2147483647; 145 | files = ( 146 | A12E70D6211AEB7D0016FA1E /* LaunchScreen.storyboard in Resources */, 147 | A12E70D3211AEB7D0016FA1E /* Assets.xcassets in Resources */, 148 | A12E70D1211AEB7D0016FA1E /* Main.storyboard in Resources */, 149 | ); 150 | runOnlyForDeploymentPostprocessing = 0; 151 | }; 152 | /* End PBXResourcesBuildPhase section */ 153 | 154 | /* Begin PBXSourcesBuildPhase section */ 155 | A12E70C4211AEB7D0016FA1E /* Sources */ = { 156 | isa = PBXSourcesBuildPhase; 157 | buildActionMask = 2147483647; 158 | files = ( 159 | A12E70CE211AEB7D0016FA1E /* ViewController.swift in Sources */, 160 | A12E70E1211AECF70016FA1E /* TTPageViewController.swift in Sources */, 161 | A12E70DF211AECB70016FA1E /* TTHeadView.swift in Sources */, 162 | A12E70E3211AEE330016FA1E /* TableViewController.swift in Sources */, 163 | A12E70CC211AEB7D0016FA1E /* AppDelegate.swift in Sources */, 164 | ); 165 | runOnlyForDeploymentPostprocessing = 0; 166 | }; 167 | /* End PBXSourcesBuildPhase section */ 168 | 169 | /* Begin PBXVariantGroup section */ 170 | A12E70CF211AEB7D0016FA1E /* Main.storyboard */ = { 171 | isa = PBXVariantGroup; 172 | children = ( 173 | A12E70D0211AEB7D0016FA1E /* Base */, 174 | ); 175 | name = Main.storyboard; 176 | sourceTree = ""; 177 | }; 178 | A12E70D4211AEB7D0016FA1E /* LaunchScreen.storyboard */ = { 179 | isa = PBXVariantGroup; 180 | children = ( 181 | A12E70D5211AEB7D0016FA1E /* Base */, 182 | ); 183 | name = LaunchScreen.storyboard; 184 | sourceTree = ""; 185 | }; 186 | /* End PBXVariantGroup section */ 187 | 188 | /* Begin XCBuildConfiguration section */ 189 | A12E70D8211AEB7D0016FA1E /* Debug */ = { 190 | isa = XCBuildConfiguration; 191 | buildSettings = { 192 | ALWAYS_SEARCH_USER_PATHS = NO; 193 | CLANG_ANALYZER_NONNULL = YES; 194 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 195 | CLANG_CXX_LIBRARY = "libc++"; 196 | CLANG_ENABLE_MODULES = YES; 197 | CLANG_ENABLE_OBJC_ARC = YES; 198 | CLANG_WARN_BOOL_CONVERSION = YES; 199 | CLANG_WARN_CONSTANT_CONVERSION = YES; 200 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 201 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 202 | CLANG_WARN_EMPTY_BODY = YES; 203 | CLANG_WARN_ENUM_CONVERSION = YES; 204 | CLANG_WARN_INFINITE_RECURSION = YES; 205 | CLANG_WARN_INT_CONVERSION = YES; 206 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 207 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 208 | CLANG_WARN_UNREACHABLE_CODE = YES; 209 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 210 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 211 | COPY_PHASE_STRIP = NO; 212 | DEBUG_INFORMATION_FORMAT = dwarf; 213 | ENABLE_STRICT_OBJC_MSGSEND = YES; 214 | ENABLE_TESTABILITY = YES; 215 | GCC_C_LANGUAGE_STANDARD = gnu99; 216 | GCC_DYNAMIC_NO_PIC = NO; 217 | GCC_NO_COMMON_BLOCKS = YES; 218 | GCC_OPTIMIZATION_LEVEL = 0; 219 | GCC_PREPROCESSOR_DEFINITIONS = ( 220 | "DEBUG=1", 221 | "$(inherited)", 222 | ); 223 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 224 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 225 | GCC_WARN_UNDECLARED_SELECTOR = YES; 226 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 227 | GCC_WARN_UNUSED_FUNCTION = YES; 228 | GCC_WARN_UNUSED_VARIABLE = YES; 229 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 230 | MTL_ENABLE_DEBUG_INFO = YES; 231 | ONLY_ACTIVE_ARCH = YES; 232 | SDKROOT = iphoneos; 233 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 234 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 235 | TARGETED_DEVICE_FAMILY = "1,2"; 236 | }; 237 | name = Debug; 238 | }; 239 | A12E70D9211AEB7D0016FA1E /* Release */ = { 240 | isa = XCBuildConfiguration; 241 | buildSettings = { 242 | ALWAYS_SEARCH_USER_PATHS = NO; 243 | CLANG_ANALYZER_NONNULL = YES; 244 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 245 | CLANG_CXX_LIBRARY = "libc++"; 246 | CLANG_ENABLE_MODULES = YES; 247 | CLANG_ENABLE_OBJC_ARC = YES; 248 | CLANG_WARN_BOOL_CONVERSION = YES; 249 | CLANG_WARN_CONSTANT_CONVERSION = YES; 250 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 251 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 252 | CLANG_WARN_EMPTY_BODY = YES; 253 | CLANG_WARN_ENUM_CONVERSION = YES; 254 | CLANG_WARN_INFINITE_RECURSION = YES; 255 | CLANG_WARN_INT_CONVERSION = YES; 256 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 257 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 258 | CLANG_WARN_UNREACHABLE_CODE = YES; 259 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 260 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 261 | COPY_PHASE_STRIP = NO; 262 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 263 | ENABLE_NS_ASSERTIONS = NO; 264 | ENABLE_STRICT_OBJC_MSGSEND = YES; 265 | GCC_C_LANGUAGE_STANDARD = gnu99; 266 | GCC_NO_COMMON_BLOCKS = YES; 267 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 268 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 269 | GCC_WARN_UNDECLARED_SELECTOR = YES; 270 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 271 | GCC_WARN_UNUSED_FUNCTION = YES; 272 | GCC_WARN_UNUSED_VARIABLE = YES; 273 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 274 | MTL_ENABLE_DEBUG_INFO = NO; 275 | SDKROOT = iphoneos; 276 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 277 | TARGETED_DEVICE_FAMILY = "1,2"; 278 | VALIDATE_PRODUCT = YES; 279 | }; 280 | name = Release; 281 | }; 282 | A12E70DB211AEB7D0016FA1E /* Debug */ = { 283 | isa = XCBuildConfiguration; 284 | buildSettings = { 285 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 286 | DEVELOPMENT_TEAM = 8R29X3H9MY; 287 | INFOPLIST_FILE = SwiftTTPageController/Info.plist; 288 | IPHONEOS_DEPLOYMENT_TARGET = 12.0; 289 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 290 | PRODUCT_BUNDLE_IDENTIFIER = "com.gener-tech.SwiftTTPageController"; 291 | PRODUCT_NAME = "$(TARGET_NAME)"; 292 | SWIFT_SWIFT3_OBJC_INFERENCE = On; 293 | SWIFT_VERSION = 5.0; 294 | }; 295 | name = Debug; 296 | }; 297 | A12E70DC211AEB7D0016FA1E /* Release */ = { 298 | isa = XCBuildConfiguration; 299 | buildSettings = { 300 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 301 | DEVELOPMENT_TEAM = 8R29X3H9MY; 302 | INFOPLIST_FILE = SwiftTTPageController/Info.plist; 303 | IPHONEOS_DEPLOYMENT_TARGET = 12.0; 304 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 305 | PRODUCT_BUNDLE_IDENTIFIER = "com.gener-tech.SwiftTTPageController"; 306 | PRODUCT_NAME = "$(TARGET_NAME)"; 307 | SWIFT_SWIFT3_OBJC_INFERENCE = On; 308 | SWIFT_VERSION = 5.0; 309 | }; 310 | name = Release; 311 | }; 312 | /* End XCBuildConfiguration section */ 313 | 314 | /* Begin XCConfigurationList section */ 315 | A12E70C3211AEB7C0016FA1E /* Build configuration list for PBXProject "SwiftTTPageController" */ = { 316 | isa = XCConfigurationList; 317 | buildConfigurations = ( 318 | A12E70D8211AEB7D0016FA1E /* Debug */, 319 | A12E70D9211AEB7D0016FA1E /* Release */, 320 | ); 321 | defaultConfigurationIsVisible = 0; 322 | defaultConfigurationName = Release; 323 | }; 324 | A12E70DA211AEB7D0016FA1E /* Build configuration list for PBXNativeTarget "SwiftTTPageController" */ = { 325 | isa = XCConfigurationList; 326 | buildConfigurations = ( 327 | A12E70DB211AEB7D0016FA1E /* Debug */, 328 | A12E70DC211AEB7D0016FA1E /* Release */, 329 | ); 330 | defaultConfigurationIsVisible = 0; 331 | defaultConfigurationName = Release; 332 | }; 333 | /* End XCConfigurationList section */ 334 | }; 335 | rootObject = A12E70C0211AEB7C0016FA1E /* Project object */; 336 | } 337 | -------------------------------------------------------------------------------- /SwiftTTPageController.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SwiftTTPageController.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /SwiftTTPageController.xcodeproj/project.xcworkspace/xcuserdata/gener.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Light413/SwiftTTPageController/5d9f74b2ad2cbe41d82484c674c58d2705ecf90d/SwiftTTPageController.xcodeproj/project.xcworkspace/xcuserdata/gener.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /SwiftTTPageController.xcodeproj/xcuserdata/gener.xcuserdatad/xcschemes/SwiftTTPageController.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /SwiftTTPageController.xcodeproj/xcuserdata/gener.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | SwiftTTPageController.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | A12E70C7211AEB7D0016FA1E 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /SwiftTTPageController/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // SwiftTTPageController 4 | // 5 | // Created by gener on 2018/8/8. 6 | // Copyright © 2018年 Light. 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 | 23 | } 24 | 25 | -------------------------------------------------------------------------------- /SwiftTTPageController/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /SwiftTTPageController/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /SwiftTTPageController/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 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /SwiftTTPageController/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 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /SwiftTTPageController/SwiftTTPageController/TTHeadView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TTHeadView.swift 3 | // SwiftTTPageController 4 | // 5 | // Created by gener on 2018/8/8. 6 | // Copyright © 2018年 Light. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @objc public protocol TTHeadViewDelegate { 12 | ///TTHeadView选中后方法回调 13 | func tt_headViewSelectedAt(_ index:Int); 14 | } 15 | 16 | public struct TTHeadTextAttribute { 17 | ///默认字体颜色 18 | public var defaultTextColor:UIColor = UIColor.darkGray 19 | ///默认字体大小 20 | public var defaultFontSize:CGFloat = 15 21 | 22 | ///选中字体颜色 23 | public var selectedTextColor:UIColor = UIColor.black 24 | ///选中字体大小 25 | public var selectedFontSize:CGFloat = 16 26 | 27 | ///是否需要下划线(默认显示) 28 | public var needBottomLine: Bool = true 29 | ///下划线颜色 30 | public var bottomLineColor:UIColor = UIColor.orange 31 | ///下划线宽度 32 | public var bottomLineWidth:CGFloat = 0 33 | ///下划线高度 34 | public var bottomLineHeight:CGFloat = 3 35 | 36 | ///itemSize宽度(默认50) 37 | public var itemWidth:CGFloat = 50 38 | 39 | ///Required 40 | public init() {} 41 | } 42 | 43 | 44 | open class TTHeadView: UIView { 45 | ///TTHeadView属性 46 | var textAttribute:TTHeadTextAttribute! 47 | 48 | fileprivate var _titles :[String]! 49 | fileprivate var _currentIndex: Int = 0//current selected 50 | fileprivate weak var _delegate:TTHeadViewDelegate? 51 | 52 | fileprivate var _collectionView:UICollectionView! 53 | fileprivate var _bottomLineWidth:CGFloat = 0 54 | fileprivate var _bottomLine:UILabel! 55 | 56 | //MARK: - Init 57 | required public init?(coder aDecoder: NSCoder) { 58 | fatalError("init(coder:) has not been implemented") 59 | } 60 | 61 | 62 | override init(frame: CGRect) { 63 | super.init(frame: frame) 64 | 65 | _collectionView = colleciontView(CGRect (x: 0, y: 0, width: frame.width, height: frame.height)) 66 | self.addSubview(_collectionView) 67 | } 68 | 69 | /// 初始化TTHeadView 70 | public init(frame:CGRect, 71 | titles:[String], 72 | delegate:TTHeadViewDelegate? = nil, 73 | textAttributes:TTHeadTextAttribute = TTHeadTextAttribute()) 74 | { 75 | super.init(frame:frame) 76 | 77 | _titles = titles 78 | _delegate = delegate 79 | textAttribute = textAttributes 80 | 81 | _collectionView = colleciontView(CGRect (x: 0, y: 0, width: frame.width, height: frame.height)) 82 | self.addSubview(_collectionView) 83 | 84 | //bottomLine 85 | if textAttributes.needBottomLine { 86 | if textAttributes.bottomLineWidth > 0 { 87 | _bottomLineWidth = textAttributes.bottomLineWidth 88 | }else{ 89 | _bottomLineWidth = textAttributes.itemWidth * 0.5 90 | } 91 | 92 | _bottomLine = UILabel (frame: CGRect (x: (textAttribute.itemWidth - _bottomLineWidth)/2, y: _collectionView.frame.height - textAttributes.bottomLineHeight, width: _bottomLineWidth, height: textAttributes.bottomLineHeight)) 93 | _bottomLine.backgroundColor = textAttribute.bottomLineColor 94 | 95 | _bottomLine.layer.cornerRadius = 2 96 | _bottomLine.layer.masksToBounds = true 97 | _collectionView.addSubview(_bottomLine) 98 | } 99 | 100 | } 101 | 102 | //MARK: 103 | /// 滑动到指定索引(供外部调用) 104 | public func scrollToItemAtIndex(_ index:Int) { 105 | _currentIndex = index 106 | _collectionView.reloadData() 107 | 108 | let item_width = (_collectionView.collectionViewLayout as! UICollectionViewFlowLayout).itemSize.width 109 | var offset = item_width * (CGFloat(index) + 0.5) - _collectionView.frame.width / 2 110 | let max = _collectionView.contentSize.width - _collectionView.frame.width + _collectionView.contentInset.left 111 | 112 | if offset < 0 { offset = -_collectionView.contentInset.left;} 113 | if offset > 0 && max > 0 && offset > max { offset = max;} 114 | 115 | let _x = CGFloat.init(index) * textAttribute.itemWidth + (item_width - 0) * 0.5 116 | 117 | if textAttribute.needBottomLine { 118 | UIView.animate(withDuration: 0.2) {[unowned self] in 119 | self._bottomLine.center = CGPoint (x: _x, y: self._bottomLine.center.y); 120 | } 121 | } 122 | 123 | //... 124 | guard CGFloat.init(_titles.count) * textAttribute.itemWidth > self.frame.width else {return } 125 | _collectionView.setContentOffset(CGPoint (x: offset, y: 0), animated: true) 126 | } 127 | 128 | ///Private 129 | fileprivate func colleciontView(_ frame:CGRect) -> UICollectionView { 130 | let _layout = UICollectionViewFlowLayout() 131 | _layout.itemSize = CGSize (width: textAttribute.itemWidth, height: frame.height) 132 | _layout.minimumInteritemSpacing = 0 133 | _layout.minimumLineSpacing = 0 134 | _layout.scrollDirection = .horizontal 135 | 136 | let collectionview = UICollectionView (frame: frame, collectionViewLayout: _layout) 137 | collectionview.delegate = self 138 | collectionview.dataSource = self 139 | collectionview.register(UICollectionViewCell.self, forCellWithReuseIdentifier: String (describing: UICollectionViewCell.self)) 140 | collectionview.showsHorizontalScrollIndicator = false 141 | collectionview.showsVerticalScrollIndicator = false 142 | collectionview.backgroundView = nil 143 | collectionview.backgroundColor = UIColor.white 144 | return collectionview 145 | } 146 | 147 | } 148 | 149 | //MARK: - UICollectionViewDataSource 150 | extension TTHeadView:UICollectionViewDelegate,UICollectionViewDataSource { 151 | 152 | public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 153 | return _titles.count 154 | } 155 | 156 | public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 157 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String (describing: UICollectionViewCell.self), for: indexPath) 158 | let v = _titles[indexPath.row] 159 | 160 | for _v in cell.contentView.subviews{ 161 | _v.removeFromSuperview(); 162 | } 163 | 164 | let l = UILabel.init(frame: CGRect (x: 0, y: 0, width: textAttribute.itemWidth, height: self.frame.height)) 165 | l.font = UIFont.systemFont(ofSize: _currentIndex == indexPath.row ? textAttribute.selectedFontSize:textAttribute.defaultFontSize, weight: UIFont.Weight.regular) 166 | l.textAlignment = .center 167 | l.text = v 168 | l.textColor = _currentIndex == indexPath.row ? textAttribute.selectedTextColor:textAttribute.defaultTextColor 169 | 170 | cell.contentView.addSubview(l) 171 | return cell 172 | } 173 | 174 | public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 175 | let index = indexPath.row 176 | guard index != _currentIndex else{ return } 177 | _currentIndex = index 178 | collectionView.reloadData() 179 | 180 | scrollToItemAtIndex(index) 181 | 182 | if let delegate = _delegate { 183 | delegate.tt_headViewSelectedAt(index) 184 | } 185 | } 186 | 187 | } 188 | -------------------------------------------------------------------------------- /SwiftTTPageController/SwiftTTPageController/TTPageViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TTPageViewController.swift 3 | // SwiftTTPageController 4 | // 5 | // Created by gener on 2018/8/8. 6 | // Copyright © 2018年 Light. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @objc public protocol TTPageViewControllerDelegate { 12 | func tt_pageControllerSelectedAt(_ index:Int) 13 | } 14 | 15 | open class TTPageViewController: UIViewController { 16 | 17 | public var _viewControllers :[UIViewController]! 18 | 19 | var currentIndex: Int = 0//current selected index 20 | 21 | weak var _delegate:TTPageViewControllerDelegate? 22 | 23 | var _collectionView:UICollectionView! 24 | 25 | //MARK: - 26 | override open func viewDidLoad() { 27 | super.viewDidLoad() 28 | // self.edgesForExtendedLayout = .top 29 | } 30 | 31 | override open func viewDidLayoutSubviews() { 32 | super.viewDidLayoutSubviews() 33 | 34 | _collectionView = self.colleciontView() 35 | view.addSubview(_collectionView) 36 | } 37 | 38 | public init(controllers:[UIViewController], frame viewFrame:CGRect,delegate:TTPageViewControllerDelegate? = nil) { 39 | super.init(nibName: nil, bundle: nil) 40 | 41 | _viewControllers = controllers 42 | _delegate = delegate 43 | view.frame = viewFrame 44 | } 45 | 46 | required public init?(coder aDecoder: NSCoder) { 47 | fatalError("init(coder:) has not been implemented") 48 | } 49 | 50 | 51 | 52 | override open func didReceiveMemoryWarning() { 53 | super.didReceiveMemoryWarning() 54 | // Dispose of any resources that can be recreated. 55 | } 56 | 57 | 58 | fileprivate func colleciontView() -> UICollectionView { 59 | let rect = CGRect (x: 0, y: 0, width: view.frame.width, height: view.frame.height) 60 | let _layout = UICollectionViewFlowLayout() 61 | _layout.itemSize = rect.size 62 | _layout.minimumInteritemSpacing = 0 63 | _layout.minimumLineSpacing = 0 64 | _layout.scrollDirection = .horizontal 65 | 66 | let collectionview = UICollectionView (frame: rect, collectionViewLayout: _layout) 67 | collectionview.delegate = self 68 | collectionview.dataSource = self 69 | collectionview.register(UICollectionViewCell.self, forCellWithReuseIdentifier: String (describing: UICollectionViewCell.self)) 70 | collectionview.backgroundColor = UIColor.white 71 | collectionview.isPagingEnabled = true 72 | collectionview.showsHorizontalScrollIndicator = false 73 | collectionview.showsVerticalScrollIndicator = false 74 | if #available(iOS 11.0, *) { 75 | collectionview.contentInsetAdjustmentBehavior = .never 76 | } else { 77 | // Fallback on earlier versions 78 | self.automaticallyAdjustsScrollViewInsets = false; 79 | } 80 | return collectionview 81 | } 82 | 83 | //Public Method 84 | public func scrollToPageAtIndex(_ index:Int) { 85 | _collectionView.scrollToItem(at: IndexPath.init(row: index, section: 0), at: .right, animated: false) 86 | } 87 | 88 | } 89 | 90 | 91 | 92 | 93 | 94 | extension TTPageViewController:UICollectionViewDelegate,UICollectionViewDataSource{ 95 | //MARK: - UICollectionViewDataSource 96 | public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 97 | return _viewControllers.count 98 | } 99 | 100 | public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 101 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String (describing: UICollectionViewCell.self), for: indexPath) 102 | let v = _viewControllers[indexPath.row] 103 | for _v in cell.contentView.subviews{ 104 | _v.removeFromSuperview(); 105 | 106 | } 107 | 108 | v.removeFromParent() 109 | v.view.frame = CGRect (x: 0, y: 0, width: view.frame.width, height: view.frame.height) 110 | 111 | self.addChild(v) 112 | cell.contentView.addSubview(v.view) 113 | return cell 114 | } 115 | 116 | 117 | public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { 118 | 119 | _scroll(scrollView); 120 | } 121 | 122 | public func scrollViewDidScroll(_ scrollView: UIScrollView) { 123 | _scroll(scrollView); 124 | } 125 | 126 | func _scroll(_ scrollView: UIScrollView) { 127 | let index = scrollView.contentOffset.x / scrollView.frame.width 128 | let i = lrintf(Float(index)) 129 | guard i != currentIndex else{ return } 130 | currentIndex = i 131 | 132 | if let delegate = _delegate { 133 | delegate.tt_pageControllerSelectedAt(i) 134 | } 135 | } 136 | 137 | } 138 | -------------------------------------------------------------------------------- /SwiftTTPageController/TableViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TableViewController.swift 3 | // SwiftTTPageController 4 | // 5 | // Created by gener on 2018/8/8. 6 | // Copyright © 2018年 Light. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class TableViewController: UITableViewController { 12 | let _colors:[UIColor] = [UIColor.red, 13 | UIColor.blue, 14 | UIColor.orange, 15 | UIColor.cyan, 16 | UIColor.yellow, 17 | UIColor.green] 18 | 19 | override func viewDidLoad() { 20 | super.viewDidLoad() 21 | 22 | let i:Int = Int.init(arc4random()%6) 23 | 24 | view.backgroundColor = _colors[i] 25 | tableView.tableFooterView = UIView() 26 | } 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /SwiftTTPageController/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // SwiftTTPageController 4 | // 5 | // Created by gener on 2018/8/8. 6 | // Copyright © 2018年 Light. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController,TTHeadViewDelegate,TTPageViewControllerDelegate { 12 | 13 | var headView:TTHeadView! 14 | var pagevc:TTPageViewController! 15 | 16 | override func viewDidLoad() { 17 | super.viewDidLoad() 18 | 19 | var attri = TTHeadTextAttribute() 20 | attri.needBottomLine = true 21 | 22 | //创建headView 23 | let titles = ["新闻","视频","最新","新闻","视频","最新","军事","头条"] 24 | headView = TTHeadView (frame: CGRect (x: 0, y: 0, width: UIScreen.main.bounds.width, height: 35), titles: titles, delegate: self ,textAttributes:attri) 25 | 26 | navigationItem.titleView = headView; 27 | 28 | //创建TTPageViewController 29 | let vcs = [TableViewController(),TableViewController(),TableViewController(),TableViewController(),TableViewController(),TableViewController(),TableViewController(),TableViewController(),] 30 | 31 | let frame = CGRect (x: 0, y: 0, width: view.frame.width, height: view.frame.height) 32 | pagevc = TTPageViewController.init(controllers: vcs, frame: frame, delegate: self) 33 | 34 | //添加到当前控制器视图 35 | self.addChild(pagevc) 36 | self.view.addSubview(pagevc.view) 37 | 38 | } 39 | 40 | /////Delegate methods 41 | func tt_headViewSelectedAt(_ index: Int) { 42 | pagevc.scrollToPageAtIndex(index) 43 | } 44 | 45 | func tt_pageControllerSelectedAt(_ index: Int) { 46 | headView.scrollToItemAtIndex(index) 47 | } 48 | 49 | } 50 | 51 | --------------------------------------------------------------------------------