├── README.md ├── SDPagesSelector.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── songdh.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── songdh.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── SDPagesSelector.xcscheme │ └── xcschememanagement.plist └── SDPagesSelector ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── Info.plist ├── SDPagesSelector ├── SDCursorView.h ├── SDCursorView.m ├── SDSelectorCell.h └── SDSelectorCell.m ├── ShowViewController.h ├── ShowViewController.m ├── ViewController.h ├── ViewController.m └── main.m /README.md: -------------------------------------------------------------------------------- 1 | # SDPagesSelector 2 | 仿网易页面选择器 3 | -------------------------------------------------------------------------------- /SDPagesSelector.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | DABB23E91D3BE0CB00DDDF6C /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = DABB23E81D3BE0CB00DDDF6C /* main.m */; }; 11 | DABB23EC1D3BE0CB00DDDF6C /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = DABB23EB1D3BE0CB00DDDF6C /* AppDelegate.m */; }; 12 | DABB23EF1D3BE0CB00DDDF6C /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DABB23EE1D3BE0CB00DDDF6C /* ViewController.m */; }; 13 | DABB23F21D3BE0CB00DDDF6C /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DABB23F01D3BE0CB00DDDF6C /* Main.storyboard */; }; 14 | DABB23F41D3BE0CB00DDDF6C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DABB23F31D3BE0CB00DDDF6C /* Assets.xcassets */; }; 15 | DABB23F71D3BE0CB00DDDF6C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DABB23F51D3BE0CB00DDDF6C /* LaunchScreen.storyboard */; }; 16 | DABB24061D3BE12F00DDDF6C /* SDCursorView.m in Sources */ = {isa = PBXBuildFile; fileRef = DABB24021D3BE12F00DDDF6C /* SDCursorView.m */; }; 17 | DABB24071D3BE12F00DDDF6C /* SDSelectorCell.m in Sources */ = {isa = PBXBuildFile; fileRef = DABB24041D3BE12F00DDDF6C /* SDSelectorCell.m */; }; 18 | DABB240A1D3BE1BD00DDDF6C /* ShowViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DABB24091D3BE1BD00DDDF6C /* ShowViewController.m */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXFileReference section */ 22 | DABB23E41D3BE0CB00DDDF6C /* SDPagesSelector.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SDPagesSelector.app; sourceTree = BUILT_PRODUCTS_DIR; }; 23 | DABB23E81D3BE0CB00DDDF6C /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 24 | DABB23EA1D3BE0CB00DDDF6C /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 25 | DABB23EB1D3BE0CB00DDDF6C /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 26 | DABB23ED1D3BE0CB00DDDF6C /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 27 | DABB23EE1D3BE0CB00DDDF6C /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 28 | DABB23F11D3BE0CB00DDDF6C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 29 | DABB23F31D3BE0CB00DDDF6C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 30 | DABB23F61D3BE0CB00DDDF6C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 31 | DABB23F81D3BE0CB00DDDF6C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 32 | DABB24011D3BE12F00DDDF6C /* SDCursorView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCursorView.h; sourceTree = ""; }; 33 | DABB24021D3BE12F00DDDF6C /* SDCursorView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCursorView.m; sourceTree = ""; }; 34 | DABB24031D3BE12F00DDDF6C /* SDSelectorCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDSelectorCell.h; sourceTree = ""; }; 35 | DABB24041D3BE12F00DDDF6C /* SDSelectorCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDSelectorCell.m; sourceTree = ""; }; 36 | DABB24081D3BE1BD00DDDF6C /* ShowViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShowViewController.h; sourceTree = ""; }; 37 | DABB24091D3BE1BD00DDDF6C /* ShowViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ShowViewController.m; sourceTree = ""; }; 38 | /* End PBXFileReference section */ 39 | 40 | /* Begin PBXFrameworksBuildPhase section */ 41 | DABB23E11D3BE0CB00DDDF6C /* Frameworks */ = { 42 | isa = PBXFrameworksBuildPhase; 43 | buildActionMask = 2147483647; 44 | files = ( 45 | ); 46 | runOnlyForDeploymentPostprocessing = 0; 47 | }; 48 | /* End PBXFrameworksBuildPhase section */ 49 | 50 | /* Begin PBXGroup section */ 51 | DABB23DB1D3BE0CB00DDDF6C = { 52 | isa = PBXGroup; 53 | children = ( 54 | DABB23E61D3BE0CB00DDDF6C /* SDPagesSelector */, 55 | DABB23E51D3BE0CB00DDDF6C /* Products */, 56 | ); 57 | sourceTree = ""; 58 | }; 59 | DABB23E51D3BE0CB00DDDF6C /* Products */ = { 60 | isa = PBXGroup; 61 | children = ( 62 | DABB23E41D3BE0CB00DDDF6C /* SDPagesSelector.app */, 63 | ); 64 | name = Products; 65 | sourceTree = ""; 66 | }; 67 | DABB23E61D3BE0CB00DDDF6C /* SDPagesSelector */ = { 68 | isa = PBXGroup; 69 | children = ( 70 | DABB23FE1D3BE12F00DDDF6C /* SDPagesSelector */, 71 | DABB23EA1D3BE0CB00DDDF6C /* AppDelegate.h */, 72 | DABB23EB1D3BE0CB00DDDF6C /* AppDelegate.m */, 73 | DABB23ED1D3BE0CB00DDDF6C /* ViewController.h */, 74 | DABB23EE1D3BE0CB00DDDF6C /* ViewController.m */, 75 | DABB24081D3BE1BD00DDDF6C /* ShowViewController.h */, 76 | DABB24091D3BE1BD00DDDF6C /* ShowViewController.m */, 77 | DABB23F01D3BE0CB00DDDF6C /* Main.storyboard */, 78 | DABB23F31D3BE0CB00DDDF6C /* Assets.xcassets */, 79 | DABB23F51D3BE0CB00DDDF6C /* LaunchScreen.storyboard */, 80 | DABB23F81D3BE0CB00DDDF6C /* Info.plist */, 81 | DABB23E71D3BE0CB00DDDF6C /* Supporting Files */, 82 | ); 83 | path = SDPagesSelector; 84 | sourceTree = ""; 85 | }; 86 | DABB23E71D3BE0CB00DDDF6C /* Supporting Files */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | DABB23E81D3BE0CB00DDDF6C /* main.m */, 90 | ); 91 | name = "Supporting Files"; 92 | sourceTree = ""; 93 | }; 94 | DABB23FE1D3BE12F00DDDF6C /* SDPagesSelector */ = { 95 | isa = PBXGroup; 96 | children = ( 97 | DABB24011D3BE12F00DDDF6C /* SDCursorView.h */, 98 | DABB24021D3BE12F00DDDF6C /* SDCursorView.m */, 99 | DABB24031D3BE12F00DDDF6C /* SDSelectorCell.h */, 100 | DABB24041D3BE12F00DDDF6C /* SDSelectorCell.m */, 101 | ); 102 | path = SDPagesSelector; 103 | sourceTree = ""; 104 | }; 105 | /* End PBXGroup section */ 106 | 107 | /* Begin PBXNativeTarget section */ 108 | DABB23E31D3BE0CB00DDDF6C /* SDPagesSelector */ = { 109 | isa = PBXNativeTarget; 110 | buildConfigurationList = DABB23FB1D3BE0CB00DDDF6C /* Build configuration list for PBXNativeTarget "SDPagesSelector" */; 111 | buildPhases = ( 112 | DABB23E01D3BE0CB00DDDF6C /* Sources */, 113 | DABB23E11D3BE0CB00DDDF6C /* Frameworks */, 114 | DABB23E21D3BE0CB00DDDF6C /* Resources */, 115 | ); 116 | buildRules = ( 117 | ); 118 | dependencies = ( 119 | ); 120 | name = SDPagesSelector; 121 | productName = SDPagesSelector; 122 | productReference = DABB23E41D3BE0CB00DDDF6C /* SDPagesSelector.app */; 123 | productType = "com.apple.product-type.application"; 124 | }; 125 | /* End PBXNativeTarget section */ 126 | 127 | /* Begin PBXProject section */ 128 | DABB23DC1D3BE0CB00DDDF6C /* Project object */ = { 129 | isa = PBXProject; 130 | attributes = { 131 | LastUpgradeCheck = 0730; 132 | ORGANIZATIONNAME = songdh; 133 | TargetAttributes = { 134 | DABB23E31D3BE0CB00DDDF6C = { 135 | CreatedOnToolsVersion = 7.3.1; 136 | }; 137 | }; 138 | }; 139 | buildConfigurationList = DABB23DF1D3BE0CB00DDDF6C /* Build configuration list for PBXProject "SDPagesSelector" */; 140 | compatibilityVersion = "Xcode 3.2"; 141 | developmentRegion = English; 142 | hasScannedForEncodings = 0; 143 | knownRegions = ( 144 | en, 145 | Base, 146 | ); 147 | mainGroup = DABB23DB1D3BE0CB00DDDF6C; 148 | productRefGroup = DABB23E51D3BE0CB00DDDF6C /* Products */; 149 | projectDirPath = ""; 150 | projectRoot = ""; 151 | targets = ( 152 | DABB23E31D3BE0CB00DDDF6C /* SDPagesSelector */, 153 | ); 154 | }; 155 | /* End PBXProject section */ 156 | 157 | /* Begin PBXResourcesBuildPhase section */ 158 | DABB23E21D3BE0CB00DDDF6C /* Resources */ = { 159 | isa = PBXResourcesBuildPhase; 160 | buildActionMask = 2147483647; 161 | files = ( 162 | DABB23F71D3BE0CB00DDDF6C /* LaunchScreen.storyboard in Resources */, 163 | DABB23F41D3BE0CB00DDDF6C /* Assets.xcassets in Resources */, 164 | DABB23F21D3BE0CB00DDDF6C /* Main.storyboard in Resources */, 165 | ); 166 | runOnlyForDeploymentPostprocessing = 0; 167 | }; 168 | /* End PBXResourcesBuildPhase section */ 169 | 170 | /* Begin PBXSourcesBuildPhase section */ 171 | DABB23E01D3BE0CB00DDDF6C /* Sources */ = { 172 | isa = PBXSourcesBuildPhase; 173 | buildActionMask = 2147483647; 174 | files = ( 175 | DABB23EF1D3BE0CB00DDDF6C /* ViewController.m in Sources */, 176 | DABB23EC1D3BE0CB00DDDF6C /* AppDelegate.m in Sources */, 177 | DABB240A1D3BE1BD00DDDF6C /* ShowViewController.m in Sources */, 178 | DABB24061D3BE12F00DDDF6C /* SDCursorView.m in Sources */, 179 | DABB23E91D3BE0CB00DDDF6C /* main.m in Sources */, 180 | DABB24071D3BE12F00DDDF6C /* SDSelectorCell.m in Sources */, 181 | ); 182 | runOnlyForDeploymentPostprocessing = 0; 183 | }; 184 | /* End PBXSourcesBuildPhase section */ 185 | 186 | /* Begin PBXVariantGroup section */ 187 | DABB23F01D3BE0CB00DDDF6C /* Main.storyboard */ = { 188 | isa = PBXVariantGroup; 189 | children = ( 190 | DABB23F11D3BE0CB00DDDF6C /* Base */, 191 | ); 192 | name = Main.storyboard; 193 | sourceTree = ""; 194 | }; 195 | DABB23F51D3BE0CB00DDDF6C /* LaunchScreen.storyboard */ = { 196 | isa = PBXVariantGroup; 197 | children = ( 198 | DABB23F61D3BE0CB00DDDF6C /* Base */, 199 | ); 200 | name = LaunchScreen.storyboard; 201 | sourceTree = ""; 202 | }; 203 | /* End PBXVariantGroup section */ 204 | 205 | /* Begin XCBuildConfiguration section */ 206 | DABB23F91D3BE0CB00DDDF6C /* Debug */ = { 207 | isa = XCBuildConfiguration; 208 | buildSettings = { 209 | ALWAYS_SEARCH_USER_PATHS = NO; 210 | CLANG_ANALYZER_NONNULL = YES; 211 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 212 | CLANG_CXX_LIBRARY = "libc++"; 213 | CLANG_ENABLE_MODULES = YES; 214 | CLANG_ENABLE_OBJC_ARC = YES; 215 | CLANG_WARN_BOOL_CONVERSION = YES; 216 | CLANG_WARN_CONSTANT_CONVERSION = YES; 217 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 218 | CLANG_WARN_EMPTY_BODY = YES; 219 | CLANG_WARN_ENUM_CONVERSION = YES; 220 | CLANG_WARN_INT_CONVERSION = YES; 221 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 222 | CLANG_WARN_UNREACHABLE_CODE = YES; 223 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 224 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 225 | COPY_PHASE_STRIP = NO; 226 | DEBUG_INFORMATION_FORMAT = dwarf; 227 | ENABLE_STRICT_OBJC_MSGSEND = YES; 228 | ENABLE_TESTABILITY = YES; 229 | GCC_C_LANGUAGE_STANDARD = gnu99; 230 | GCC_DYNAMIC_NO_PIC = NO; 231 | GCC_NO_COMMON_BLOCKS = YES; 232 | GCC_OPTIMIZATION_LEVEL = 0; 233 | GCC_PREPROCESSOR_DEFINITIONS = ( 234 | "DEBUG=1", 235 | "$(inherited)", 236 | ); 237 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 238 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 239 | GCC_WARN_UNDECLARED_SELECTOR = YES; 240 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 241 | GCC_WARN_UNUSED_FUNCTION = YES; 242 | GCC_WARN_UNUSED_VARIABLE = YES; 243 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 244 | MTL_ENABLE_DEBUG_INFO = YES; 245 | ONLY_ACTIVE_ARCH = YES; 246 | SDKROOT = iphoneos; 247 | }; 248 | name = Debug; 249 | }; 250 | DABB23FA1D3BE0CB00DDDF6C /* Release */ = { 251 | isa = XCBuildConfiguration; 252 | buildSettings = { 253 | ALWAYS_SEARCH_USER_PATHS = NO; 254 | CLANG_ANALYZER_NONNULL = YES; 255 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 256 | CLANG_CXX_LIBRARY = "libc++"; 257 | CLANG_ENABLE_MODULES = YES; 258 | CLANG_ENABLE_OBJC_ARC = YES; 259 | CLANG_WARN_BOOL_CONVERSION = YES; 260 | CLANG_WARN_CONSTANT_CONVERSION = YES; 261 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 262 | CLANG_WARN_EMPTY_BODY = YES; 263 | CLANG_WARN_ENUM_CONVERSION = YES; 264 | CLANG_WARN_INT_CONVERSION = YES; 265 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 266 | CLANG_WARN_UNREACHABLE_CODE = YES; 267 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 268 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 269 | COPY_PHASE_STRIP = NO; 270 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 271 | ENABLE_NS_ASSERTIONS = NO; 272 | ENABLE_STRICT_OBJC_MSGSEND = YES; 273 | GCC_C_LANGUAGE_STANDARD = gnu99; 274 | GCC_NO_COMMON_BLOCKS = YES; 275 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 276 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 277 | GCC_WARN_UNDECLARED_SELECTOR = YES; 278 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 279 | GCC_WARN_UNUSED_FUNCTION = YES; 280 | GCC_WARN_UNUSED_VARIABLE = YES; 281 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 282 | MTL_ENABLE_DEBUG_INFO = NO; 283 | SDKROOT = iphoneos; 284 | VALIDATE_PRODUCT = YES; 285 | }; 286 | name = Release; 287 | }; 288 | DABB23FC1D3BE0CB00DDDF6C /* Debug */ = { 289 | isa = XCBuildConfiguration; 290 | buildSettings = { 291 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 292 | INFOPLIST_FILE = SDPagesSelector/Info.plist; 293 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 294 | PRODUCT_BUNDLE_IDENTIFIER = com.songdh.SDPagesSelector; 295 | PRODUCT_NAME = "$(TARGET_NAME)"; 296 | }; 297 | name = Debug; 298 | }; 299 | DABB23FD1D3BE0CB00DDDF6C /* Release */ = { 300 | isa = XCBuildConfiguration; 301 | buildSettings = { 302 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 303 | INFOPLIST_FILE = SDPagesSelector/Info.plist; 304 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 305 | PRODUCT_BUNDLE_IDENTIFIER = com.songdh.SDPagesSelector; 306 | PRODUCT_NAME = "$(TARGET_NAME)"; 307 | }; 308 | name = Release; 309 | }; 310 | /* End XCBuildConfiguration section */ 311 | 312 | /* Begin XCConfigurationList section */ 313 | DABB23DF1D3BE0CB00DDDF6C /* Build configuration list for PBXProject "SDPagesSelector" */ = { 314 | isa = XCConfigurationList; 315 | buildConfigurations = ( 316 | DABB23F91D3BE0CB00DDDF6C /* Debug */, 317 | DABB23FA1D3BE0CB00DDDF6C /* Release */, 318 | ); 319 | defaultConfigurationIsVisible = 0; 320 | defaultConfigurationName = Release; 321 | }; 322 | DABB23FB1D3BE0CB00DDDF6C /* Build configuration list for PBXNativeTarget "SDPagesSelector" */ = { 323 | isa = XCConfigurationList; 324 | buildConfigurations = ( 325 | DABB23FC1D3BE0CB00DDDF6C /* Debug */, 326 | DABB23FD1D3BE0CB00DDDF6C /* Release */, 327 | ); 328 | defaultConfigurationIsVisible = 0; 329 | defaultConfigurationName = Release; 330 | }; 331 | /* End XCConfigurationList section */ 332 | }; 333 | rootObject = DABB23DC1D3BE0CB00DDDF6C /* Project object */; 334 | } 335 | -------------------------------------------------------------------------------- /SDPagesSelector.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SDPagesSelector.xcodeproj/project.xcworkspace/xcuserdata/songdh.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/songdh/SDPagesSelector/04c96935fdb653cf4185897aab132d5ef0992dc9/SDPagesSelector.xcodeproj/project.xcworkspace/xcuserdata/songdh.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /SDPagesSelector.xcodeproj/xcuserdata/songdh.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 14 | 15 | 16 | 18 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /SDPagesSelector.xcodeproj/xcuserdata/songdh.xcuserdatad/xcschemes/SDPagesSelector.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 | -------------------------------------------------------------------------------- /SDPagesSelector.xcodeproj/xcuserdata/songdh.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | SDPagesSelector.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | DABB23E31D3BE0CB00DDDF6C 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /SDPagesSelector/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // SDPagesSelector 4 | // 5 | // Created by 宋东昊 on 16/7/17. 6 | // Copyright © 2016年 songdh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /SDPagesSelector/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // SDPagesSelector 4 | // 5 | // Created by 宋东昊 on 16/7/17. 6 | // Copyright © 2016年 songdh. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // 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. 25 | // 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. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // 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. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // 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. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /SDPagesSelector/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 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /SDPagesSelector/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 | -------------------------------------------------------------------------------- /SDPagesSelector/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 | -------------------------------------------------------------------------------- /SDPagesSelector/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 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /SDPagesSelector/SDPagesSelector/SDCursorView.h: -------------------------------------------------------------------------------- 1 | // 2 | // SDCursorView.h 3 | // SDPagesSelector 4 | // 5 | // Created by 宋东昊 on 16/7/15. 6 | // Copyright © 2016年 songdh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SDCursorView : UIView 12 | /** 13 | * 底部标识线 14 | */ 15 | @property (nonatomic, strong) UIView *lineView; 16 | 17 | /** 18 | * 当前页面所在的controller,必须赋值 19 | */ 20 | @property (nonatomic, strong) UIViewController *parentViewController; 21 | /** 22 | * 底部切换页面的容器高度 23 | */ 24 | @property (nonatomic, assign) CGFloat contentViewHeight; 25 | 26 | /** 27 | * 标题和显示的页面,数量必须相等。 28 | */ 29 | @property (nonatomic, copy) NSArray *titles; 30 | /** 31 | * 所要添加的viewController的实例。绘制界面时,会将viewController的view添加在scrollView上 32 | */ 33 | @property (nonatomic, copy) NSArray *controllers; 34 | 35 | /** 36 | * 默认分别是 [UIColor redColor],[UIColor whiteColor] 37 | */ 38 | @property (nonatomic, strong) UIColor *selectedColor; 39 | @property (nonatomic, strong) UIColor *normalColor; 40 | 41 | /** 42 | * 默认都是14号字体 43 | */ 44 | @property (nonatomic, strong) UIFont *selectedFont; 45 | @property (nonatomic, strong) UIFont *normalFont; 46 | 47 | /** 48 | * 当前选中的index。可以设置当前的index 49 | */ 50 | @property (nonatomic, assign) NSInteger currentIndex; 51 | /** 52 | * 分割线位置调整。总是居中显示 默认(0,3,2,3) 53 | 分割线默认高度为3, left可调整宽度,top可调整高度,bottom可调整lineView的y值 54 | */ 55 | @property (nonatomic, assign) UIEdgeInsets lineEdgeInsets; 56 | /** 57 | * 选择区域调整。默认(0,10,0,10) 58 | */ 59 | @property (nonatomic, assign) UIEdgeInsets cursorEdgeInsets; 60 | /** 61 | * 必须调用此方法来绘制界面 62 | */ 63 | -(void)reloadPages; 64 | @end 65 | -------------------------------------------------------------------------------- /SDPagesSelector/SDPagesSelector/SDCursorView.m: -------------------------------------------------------------------------------- 1 | // 2 | // SDCursorView.m 3 | // SDPagesSelector 4 | // 5 | // Created by 宋东昊 on 16/7/15. 6 | // Copyright © 2016年 songdh. All rights reserved. 7 | // 8 | 9 | #import "SDCursorView.h" 10 | #import "SDSelectorCell.h" 11 | 12 | static NSString *const cellIdentifier = @"selectorCell"; 13 | 14 | @interface SDCursorView () 15 | @property (nonatomic, strong) UICollectionView *collectionView; 16 | @property (nonatomic, strong) UICollectionViewFlowLayout *layout; 17 | @property (nonatomic, strong) UIScrollView *rootScrollView; 18 | 19 | @end 20 | 21 | @implementation SDCursorView 22 | 23 | -(instancetype)initWithFrame:(CGRect)frame 24 | { 25 | if (self = [super initWithFrame:frame]) { 26 | self.backgroundColor = [UIColor whiteColor]; 27 | //设置颜色默认值 28 | _normalFont = _selectedFont = [UIFont systemFontOfSize:14]; 29 | _normalColor = [UIColor blackColor]; 30 | _selectedColor = [UIColor redColor]; 31 | _currentIndex = 0; 32 | _lineEdgeInsets = UIEdgeInsetsMake(0, 3, 2, 3); 33 | _cursorEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10); 34 | 35 | } 36 | return self; 37 | } 38 | 39 | 40 | #pragma mark - SETUP UI 41 | -(UIScrollView*)rootScrollView 42 | { 43 | if (!_rootScrollView) { 44 | _rootScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(self.bounds), CGRectGetWidth(self.bounds), self.contentViewHeight)]; 45 | _rootScrollView.backgroundColor = [UIColor whiteColor]; 46 | _rootScrollView.pagingEnabled = YES; 47 | _rootScrollView.delegate = self; 48 | _rootScrollView.alwaysBounceHorizontal = YES; 49 | _rootScrollView.showsVerticalScrollIndicator = NO; 50 | _rootScrollView.showsHorizontalScrollIndicator = NO; 51 | _rootScrollView.scrollsToTop = NO; 52 | _rootScrollView.bounces = YES; 53 | [self.parentViewController.view addSubview:_rootScrollView]; 54 | 55 | NSAssert(self.parentViewController, @"self.parentViewController must has a value"); 56 | 57 | } 58 | return _rootScrollView; 59 | } 60 | 61 | -(UIView*)lineView 62 | { 63 | if (!_lineView) { 64 | _lineView = [[UIView alloc]init]; 65 | _lineView.backgroundColor = [UIColor purpleColor]; 66 | [self.collectionView addSubview:_lineView]; 67 | } 68 | return _lineView; 69 | } 70 | 71 | -(UICollectionView*)collectionView 72 | { 73 | if (!_collectionView) { 74 | _layout = [[UICollectionViewFlowLayout alloc]init]; 75 | _layout.minimumLineSpacing = 0; 76 | _layout.minimumInteritemSpacing = 0; 77 | _layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; 78 | 79 | CGRect rect = CGRectMake(_cursorEdgeInsets.left, _cursorEdgeInsets.top, CGRectGetWidth(self.bounds)-_cursorEdgeInsets.left-_cursorEdgeInsets.right, CGRectGetHeight(self.bounds)-_cursorEdgeInsets.top-_cursorEdgeInsets.bottom); 80 | _collectionView = [[UICollectionView alloc]initWithFrame:rect collectionViewLayout:_layout]; 81 | _collectionView.showsVerticalScrollIndicator = NO; 82 | _collectionView.showsHorizontalScrollIndicator = NO; 83 | _collectionView.scrollsToTop = NO; 84 | _collectionView.backgroundColor = [UIColor whiteColor]; 85 | _collectionView.delegate = self; 86 | _collectionView.dataSource = self; 87 | [_collectionView registerClass:[SDSelectorCell class] forCellWithReuseIdentifier:cellIdentifier]; 88 | [self addSubview:_collectionView]; 89 | } 90 | return _collectionView; 91 | } 92 | 93 | 94 | -(void)reloadPages 95 | { 96 | NSAssert(_titles.count == _controllers.count, @"titles' count is not equal to controllerNames' count"); 97 | [self.collectionView reloadData]; 98 | 99 | [self addChildViewController]; 100 | } 101 | 102 | -(void)setTitles:(NSArray *)titles 103 | { 104 | _titles = titles; 105 | self.rootScrollView.contentSize = CGSizeMake(CGRectGetWidth(self.bounds)*self.titles.count, 100); 106 | } 107 | 108 | /** 109 | * 将子viewController添加到scrollView上 110 | */ 111 | -(void)addChildViewController 112 | { 113 | //viewController 114 | UIViewController *controller = _controllers[_currentIndex]; 115 | 116 | CGFloat startX = CGRectGetWidth(self.rootScrollView.bounds)*_currentIndex; 117 | if (!controller.parentViewController) { 118 | [self.parentViewController addChildViewController:controller]; 119 | CGRect rect = self.rootScrollView.bounds; 120 | rect.origin.x = startX; 121 | controller.view.frame = rect; 122 | [self.rootScrollView addSubview:controller.view]; 123 | [controller didMoveToParentViewController:self.parentViewController]; 124 | } 125 | 126 | [self.rootScrollView setContentOffset:CGPointMake(startX, 0) animated:NO]; 127 | 128 | } 129 | 130 | /** 131 | * 设置collectionView的偏移量,使得选中的项目居中 132 | * 133 | * @param frame cellFrame 134 | */ 135 | -(void)setContentOffsetWithCellFrame:(CGRect)frame 136 | { 137 | CGFloat width = CGRectGetWidth(self.collectionView.frame)/2; 138 | CGFloat offsetX = 0; 139 | 140 | if (CGRectGetMidX(frame) <= width) { 141 | 142 | offsetX = 0; 143 | 144 | }else if (CGRectGetMidX(frame) + width >= self.collectionView.contentSize.width) { 145 | 146 | offsetX = self.collectionView.contentSize.width - CGRectGetWidth(self.collectionView.frame); 147 | 148 | }else{ 149 | offsetX = CGRectGetMidX(frame)-CGRectGetWidth(self.collectionView.frame)/2; 150 | } 151 | [self.collectionView setContentOffset:CGPointMake(offsetX, 0) animated:YES]; 152 | } 153 | /** 154 | * 设置标识线的frame 155 | * 156 | * @param frame cellFrame 157 | */ 158 | -(void)resizeLineViewWihtCellFrame:(CGRect)frame animated:(BOOL)animated 159 | { 160 | CGFloat height = 3.0f; 161 | CGRect rect = CGRectMake(CGRectGetMinX(frame)+_lineEdgeInsets.left, 162 | CGRectGetHeight(self.collectionView.frame)-height-_lineEdgeInsets.bottom, 163 | CGRectGetWidth(frame)-_lineEdgeInsets.left*2, height-_lineEdgeInsets.top); 164 | 165 | if (animated) { 166 | [UIView animateWithDuration:0.3f animations:^{ 167 | self.lineView.frame = rect; 168 | }]; 169 | }else{ 170 | self.lineView.frame = rect; 171 | } 172 | 173 | } 174 | /** 175 | * 主动设置cursor选中item 176 | * 177 | * @param index index 178 | */ 179 | -(void)selectItemAtIndex:(NSInteger)index 180 | { 181 | NSIndexPath *indexPath = [NSIndexPath indexPathForItem:_currentIndex inSection:0]; 182 | [self.collectionView selectItemAtIndexPath:indexPath 183 | animated:YES 184 | scrollPosition:UICollectionViewScrollPositionCenteredHorizontally]; 185 | [self selectItemAtIndexPath:indexPath]; 186 | 187 | } 188 | /** 189 | * 设置计算选中的item状态 190 | * 191 | * @param indexPath indexPath 192 | */ 193 | -(void)selectItemAtIndexPath:(NSIndexPath*)indexPath 194 | { 195 | SDSelectorCell *cell = (SDSelectorCell*)[self.collectionView cellForItemAtIndexPath:indexPath]; 196 | cell.selected = YES; 197 | CGRect rect = cell.frame; 198 | if (!cell) { 199 | UICollectionViewLayoutAttributes *attributes = [self.collectionView layoutAttributesForItemAtIndexPath:indexPath]; 200 | rect = attributes.frame; 201 | } 202 | 203 | if (CGRectGetWidth(self.collectionView.frame) < self.collectionView.contentSize.width) { 204 | [self setContentOffsetWithCellFrame:rect]; 205 | } 206 | [self resizeLineViewWihtCellFrame:rect animated:YES]; 207 | 208 | [self addChildViewController]; 209 | } 210 | /** 211 | * 主动设置使item变为不可选 212 | * 213 | * @param index index 214 | */ 215 | -(void)deselectItemAtIndex:(NSInteger)index 216 | { 217 | NSIndexPath *indexPath = [NSIndexPath indexPathForItem:index inSection:0]; 218 | [self.collectionView deselectItemAtIndexPath:indexPath animated:NO]; 219 | SDSelectorCell *cell = (SDSelectorCell*)[self.collectionView cellForItemAtIndexPath:indexPath]; 220 | cell.selected = NO; 221 | } 222 | 223 | 224 | #pragma mark - UIScrollViewDelegate 225 | - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView 226 | { 227 | if ([self.rootScrollView isEqual:scrollView]) { 228 | CGFloat offsetX = scrollView.contentOffset.x; 229 | if (offsetX >= 0) { 230 | NSInteger index = offsetX / CGRectGetWidth(self.bounds); 231 | if (self.currentIndex != index) { 232 | [self deselectItemAtIndex:self.currentIndex]; 233 | self.currentIndex = index; 234 | [self selectItemAtIndex:self.currentIndex]; 235 | } 236 | } 237 | } 238 | } 239 | 240 | 241 | #pragma mark - UICollectionViewDataSource 242 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 243 | { 244 | return _titles.count; 245 | } 246 | 247 | // The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath: 248 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 249 | { 250 | SDSelectorCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; 251 | NSString *title = _titles[indexPath.item]; 252 | cell.title = title; 253 | cell.normalFont = self.normalFont; 254 | cell.selectedFont = self.selectedFont; 255 | cell.normalColor = self.normalColor; 256 | cell.selectedColor = self.selectedColor; 257 | 258 | cell.selected = (indexPath.item == _currentIndex); 259 | 260 | 261 | if (collectionView.indexPathsForSelectedItems.count <= 0) { 262 | [self.collectionView selectItemAtIndexPath:[NSIndexPath indexPathForItem:_currentIndex inSection:0] 263 | animated:NO 264 | scrollPosition:UICollectionViewScrollPositionNone]; 265 | 266 | [self resizeLineViewWihtCellFrame:cell.frame animated:NO]; 267 | } 268 | return cell; 269 | } 270 | 271 | - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 272 | { 273 | if (_currentIndex == indexPath.item) { 274 | return; 275 | } 276 | 277 | self.currentIndex = indexPath.item; 278 | 279 | [self selectItemAtIndexPath:indexPath]; 280 | } 281 | 282 | - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath 283 | { 284 | SDSelectorCell *cell = (SDSelectorCell*)[collectionView cellForItemAtIndexPath:indexPath]; 285 | cell.selected = NO; 286 | } 287 | 288 | 289 | #pragma mark - UICollectionViewDelegateFlowLayout 290 | 291 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath 292 | { 293 | NSString *title = _titles[indexPath.item]; 294 | CGSize size = [title sizeWithAttributes:@{NSFontAttributeName:self.selectedFont}]; 295 | size = CGSizeMake(size.width+36, CGRectGetHeight(self.bounds)); 296 | 297 | return size; 298 | } 299 | 300 | - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section 301 | { 302 | return UIEdgeInsetsMake(0, 0, 0, 0); 303 | } 304 | 305 | 306 | @end 307 | -------------------------------------------------------------------------------- /SDPagesSelector/SDPagesSelector/SDSelectorCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // SDSelectorCell.h 3 | // SDPagesSelector 4 | // 5 | // Created by 宋东昊 on 16/7/15. 6 | // Copyright © 2016年 songdh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SDSelectorCell : UICollectionViewCell 12 | @property (nonatomic, copy) NSString *title; 13 | /** 14 | * 默认分别是 [UIColor redColor],[UIColor whiteColor] 15 | */ 16 | @property (nonatomic, strong) UIColor *selectedColor; 17 | @property (nonatomic, strong) UIColor *normalColor; 18 | 19 | /** 20 | * 默认都是14号字体 21 | */ 22 | @property (nonatomic, strong) UIFont *selectedFont; 23 | @property (nonatomic, strong) UIFont *normalFont; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /SDPagesSelector/SDPagesSelector/SDSelectorCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // SDSelectorCell.m 3 | // SDPagesSelector 4 | // 5 | // Created by 宋东昊 on 16/7/15. 6 | // Copyright © 2016年 songdh. All rights reserved. 7 | // 8 | 9 | #import "SDSelectorCell.h" 10 | 11 | @interface SDSelectorCell () 12 | @property (nonatomic, strong) UILabel *titleLabel; 13 | @end 14 | 15 | @implementation SDSelectorCell 16 | -(instancetype)initWithFrame:(CGRect)frame 17 | { 18 | if (self = [super initWithFrame:frame]) { 19 | self.backgroundColor = [UIColor whiteColor]; 20 | 21 | _selectedColor = [UIColor redColor]; 22 | _normalColor = [UIColor whiteColor]; 23 | _selectedFont = _normalFont = [UIFont systemFontOfSize:14]; 24 | 25 | _titleLabel = [[UILabel alloc]init]; 26 | _titleLabel.textAlignment = NSTextAlignmentCenter; 27 | _titleLabel.backgroundColor = [UIColor whiteColor]; 28 | [self.contentView addSubview:_titleLabel]; 29 | } 30 | return self; 31 | } 32 | 33 | -(void)setTitle:(NSString *)title 34 | { 35 | _title = title; 36 | _titleLabel.text = _title; 37 | } 38 | 39 | -(void)setSelected:(BOOL)selected 40 | { 41 | super.selected = selected; 42 | if (selected) { 43 | _titleLabel.font = _selectedFont; 44 | _titleLabel.textColor = _selectedColor; 45 | }else{ 46 | _titleLabel.font = _normalFont; 47 | _titleLabel.textColor = _normalColor; 48 | } 49 | } 50 | 51 | -(void)layoutSubviews 52 | { 53 | [super layoutSubviews]; 54 | _titleLabel.frame = self.bounds; 55 | } 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /SDPagesSelector/ShowViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ShowViewController.h 3 | // SDPagesSelector 4 | // 5 | // Created by 宋东昊 on 16/7/15. 6 | // Copyright © 2016年 songdh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ShowViewController : UIViewController 12 | @property (nonatomic, copy) NSString *content; 13 | @end 14 | -------------------------------------------------------------------------------- /SDPagesSelector/ShowViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ShowViewController.m 3 | // SDPagesSelector 4 | // 5 | // Created by 宋东昊 on 16/7/15. 6 | // Copyright © 2016年 songdh. All rights reserved. 7 | // 8 | 9 | #import "ShowViewController.h" 10 | 11 | @interface ShowViewController () 12 | @property (nonatomic, strong) UILabel *contentLabel; 13 | @end 14 | 15 | @implementation ShowViewController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | // Do any additional setup after loading the view. 20 | self.view.backgroundColor = [self randomColor]; 21 | 22 | _contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 200)]; 23 | _contentLabel.center = self.view.center; 24 | _contentLabel.textColor = [UIColor redColor]; 25 | _contentLabel.textAlignment = NSTextAlignmentCenter; 26 | _contentLabel.text = self.content; 27 | [self.view addSubview:_contentLabel]; 28 | } 29 | 30 | 31 | - (void)didReceiveMemoryWarning { 32 | [super didReceiveMemoryWarning]; 33 | // Dispose of any resources that can be recreated. 34 | } 35 | 36 | - (UIColor *)randomColor 37 | { 38 | static BOOL seeded = NO; 39 | if(!seeded) { 40 | seeded = YES; 41 | srandom((unsigned)time(NULL)); 42 | } 43 | CGFloat red = (CGFloat)random()/(CGFloat)RAND_MAX; 44 | CGFloat blue = (CGFloat)random()/(CGFloat)RAND_MAX; 45 | CGFloat green = (CGFloat)random()/(CGFloat)RAND_MAX; 46 | return [UIColor colorWithRed:red green:green blue:blue alpha:1.0f]; 47 | } 48 | /* 49 | #pragma mark - Navigation 50 | 51 | // In a storyboard-based application, you will often want to do a little preparation before navigation 52 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 53 | // Get the new view controller using [segue destinationViewController]. 54 | // Pass the selected object to the new view controller. 55 | } 56 | */ 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /SDPagesSelector/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // SDPagesSelector 4 | // 5 | // Created by 宋东昊 on 16/7/17. 6 | // Copyright © 2016年 songdh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /SDPagesSelector/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // SDPagesSelector 4 | // 5 | // Created by 宋东昊 on 16/7/17. 6 | // Copyright © 2016年 songdh. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "SDCursorView.h" 11 | #import "ShowViewController.h" 12 | 13 | @interface ViewController () 14 | @property (nonatomic, strong) SDCursorView *cursorView; 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view, typically from a nib. 22 | self.view.backgroundColor = [UIColor whiteColor]; 23 | 24 | NSArray *titles = @[@"头条",@"大数据股票财经",@"精选",@"娱乐视",@"热点点附近会计分录的",@"体育",@"科技",@"汽车"]; 25 | _cursorView = [[SDCursorView alloc]initWithFrame:CGRectMake(0, 20, CGRectGetWidth(self.view.bounds), 40)]; 26 | //设置子页面容器的高度 27 | _cursorView.contentViewHeight = CGRectGetHeight(self.view.bounds)-40; 28 | //设置控件所在controller 29 | _cursorView.parentViewController = self; 30 | _cursorView.titles = titles; 31 | 32 | //设置所有子controller 33 | NSMutableArray *contrors = [NSMutableArray array]; 34 | for (NSString *title in titles) { 35 | ShowViewController *controller = [[ShowViewController alloc]init]; 36 | controller.content = title; 37 | [contrors addObject:controller]; 38 | } 39 | _cursorView.controllers = [contrors copy]; 40 | //设置字体和颜色 41 | _cursorView.normalColor = [UIColor blackColor]; 42 | _cursorView.selectedColor = [UIColor redColor]; 43 | _cursorView.selectedFont = [UIFont systemFontOfSize:16]; 44 | _cursorView.normalFont = [UIFont systemFontOfSize:13]; 45 | _cursorView.backgroundColor = [UIColor redColor]; 46 | _cursorView.lineView.backgroundColor = [UIColor redColor]; 47 | 48 | [self.view addSubview:_cursorView]; 49 | 50 | //属性设置完成后,调用此方法绘制界面 51 | [_cursorView reloadPages]; 52 | } 53 | 54 | - (void)didReceiveMemoryWarning { 55 | [super didReceiveMemoryWarning]; 56 | // Dispose of any resources that can be recreated. 57 | } 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /SDPagesSelector/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // SDPagesSelector 4 | // 5 | // Created by 宋东昊 on 16/7/17. 6 | // Copyright © 2016年 songdh. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | --------------------------------------------------------------------------------