├── .gitignore ├── 2015-08-30_16_49_40.gif ├── JRSegmentControl.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── JRSegmentControl.xccheckout │ └── xcuserdata │ │ └── zhanjiarong.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── zhanjiarong.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── JRSegmentControl.xcscheme │ └── xcschememanagement.plist ├── JRSegmentControl ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── Classes │ ├── FirstViewController.h │ ├── FirstViewController.m │ ├── FirstViewController.xib │ ├── SecondViewController.h │ ├── SecondViewController.m │ ├── SecondViewController.xib │ ├── ThirdViewController.h │ ├── ThirdViewController.m │ └── ThirdViewController.xib ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── JRSegmentControl │ ├── JRSegmentControl.h │ ├── JRSegmentControl.m │ ├── JRSegmentViewController.h │ └── JRSegmentViewController.m ├── ViewController.h ├── ViewController.m └── main.m ├── JRSegmentControlTests ├── Info.plist └── JRSegmentControlTests.m ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /2015-08-30_16_49_40.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhanjiarong/JRSegmentControl/59da21e85d023b38cde98d8a35d4b813abeb0d62/2015-08-30_16_49_40.gif -------------------------------------------------------------------------------- /JRSegmentControl.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | C00BF0D41B92E6C30010A514 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = C00BF0D31B92E6C30010A514 /* main.m */; }; 11 | C00BF0D71B92E6C30010A514 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C00BF0D61B92E6C30010A514 /* AppDelegate.m */; }; 12 | C00BF0DA1B92E6C30010A514 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C00BF0D91B92E6C30010A514 /* ViewController.m */; }; 13 | C00BF0DD1B92E6C30010A514 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C00BF0DB1B92E6C30010A514 /* Main.storyboard */; }; 14 | C00BF0DF1B92E6C30010A514 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C00BF0DE1B92E6C30010A514 /* Images.xcassets */; }; 15 | C00BF0E21B92E6C30010A514 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = C00BF0E01B92E6C30010A514 /* LaunchScreen.xib */; }; 16 | C00BF0EE1B92E6C30010A514 /* JRSegmentControlTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C00BF0ED1B92E6C30010A514 /* JRSegmentControlTests.m */; }; 17 | C00BF0FD1B92E74E0010A514 /* JRSegmentViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C00BF0FC1B92E74E0010A514 /* JRSegmentViewController.m */; }; 18 | C00BF1091B92E7790010A514 /* FirstViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C00BF1011B92E7790010A514 /* FirstViewController.m */; }; 19 | C00BF10A1B92E7790010A514 /* FirstViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = C00BF1021B92E7790010A514 /* FirstViewController.xib */; }; 20 | C00BF10B1B92E7790010A514 /* SecondViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C00BF1041B92E7790010A514 /* SecondViewController.m */; }; 21 | C00BF10C1B92E7790010A514 /* SecondViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = C00BF1051B92E7790010A514 /* SecondViewController.xib */; }; 22 | C00BF10D1B92E7790010A514 /* ThirdViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C00BF1071B92E7790010A514 /* ThirdViewController.m */; }; 23 | C00BF10E1B92E7790010A514 /* ThirdViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = C00BF1081B92E7790010A514 /* ThirdViewController.xib */; }; 24 | C0B81F5D1C2D482900CBC79A /* JRSegmentControl.m in Sources */ = {isa = PBXBuildFile; fileRef = C0B81F5C1C2D482900CBC79A /* JRSegmentControl.m */; }; 25 | /* End PBXBuildFile section */ 26 | 27 | /* Begin PBXContainerItemProxy section */ 28 | C00BF0E81B92E6C30010A514 /* PBXContainerItemProxy */ = { 29 | isa = PBXContainerItemProxy; 30 | containerPortal = C00BF0C61B92E6C30010A514 /* Project object */; 31 | proxyType = 1; 32 | remoteGlobalIDString = C00BF0CD1B92E6C30010A514; 33 | remoteInfo = JRSegmentControl; 34 | }; 35 | /* End PBXContainerItemProxy section */ 36 | 37 | /* Begin PBXFileReference section */ 38 | C00BF0CE1B92E6C30010A514 /* JRSegmentControl.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JRSegmentControl.app; sourceTree = BUILT_PRODUCTS_DIR; }; 39 | C00BF0D21B92E6C30010A514 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 40 | C00BF0D31B92E6C30010A514 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 41 | C00BF0D51B92E6C30010A514 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 42 | C00BF0D61B92E6C30010A514 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 43 | C00BF0D81B92E6C30010A514 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 44 | C00BF0D91B92E6C30010A514 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 45 | C00BF0DC1B92E6C30010A514 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 46 | C00BF0DE1B92E6C30010A514 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 47 | C00BF0E11B92E6C30010A514 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 48 | C00BF0E71B92E6C30010A514 /* JRSegmentControlTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = JRSegmentControlTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 49 | C00BF0EC1B92E6C30010A514 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 50 | C00BF0ED1B92E6C30010A514 /* JRSegmentControlTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JRSegmentControlTests.m; sourceTree = ""; }; 51 | C00BF0FB1B92E74E0010A514 /* JRSegmentViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JRSegmentViewController.h; sourceTree = ""; }; 52 | C00BF0FC1B92E74E0010A514 /* JRSegmentViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JRSegmentViewController.m; sourceTree = ""; }; 53 | C00BF1001B92E7790010A514 /* FirstViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FirstViewController.h; sourceTree = ""; }; 54 | C00BF1011B92E7790010A514 /* FirstViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FirstViewController.m; sourceTree = ""; }; 55 | C00BF1021B92E7790010A514 /* FirstViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = FirstViewController.xib; sourceTree = ""; }; 56 | C00BF1031B92E7790010A514 /* SecondViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecondViewController.h; sourceTree = ""; }; 57 | C00BF1041B92E7790010A514 /* SecondViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SecondViewController.m; sourceTree = ""; }; 58 | C00BF1051B92E7790010A514 /* SecondViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SecondViewController.xib; sourceTree = ""; }; 59 | C00BF1061B92E7790010A514 /* ThirdViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThirdViewController.h; sourceTree = ""; }; 60 | C00BF1071B92E7790010A514 /* ThirdViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ThirdViewController.m; sourceTree = ""; }; 61 | C00BF1081B92E7790010A514 /* ThirdViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ThirdViewController.xib; sourceTree = ""; }; 62 | C0B81F5B1C2D482900CBC79A /* JRSegmentControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JRSegmentControl.h; sourceTree = ""; }; 63 | C0B81F5C1C2D482900CBC79A /* JRSegmentControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JRSegmentControl.m; sourceTree = ""; }; 64 | /* End PBXFileReference section */ 65 | 66 | /* Begin PBXFrameworksBuildPhase section */ 67 | C00BF0CB1B92E6C30010A514 /* Frameworks */ = { 68 | isa = PBXFrameworksBuildPhase; 69 | buildActionMask = 2147483647; 70 | files = ( 71 | ); 72 | runOnlyForDeploymentPostprocessing = 0; 73 | }; 74 | C00BF0E41B92E6C30010A514 /* Frameworks */ = { 75 | isa = PBXFrameworksBuildPhase; 76 | buildActionMask = 2147483647; 77 | files = ( 78 | ); 79 | runOnlyForDeploymentPostprocessing = 0; 80 | }; 81 | /* End PBXFrameworksBuildPhase section */ 82 | 83 | /* Begin PBXGroup section */ 84 | C00BF0C51B92E6C30010A514 = { 85 | isa = PBXGroup; 86 | children = ( 87 | C00BF0D01B92E6C30010A514 /* JRSegmentControl */, 88 | C00BF0EA1B92E6C30010A514 /* JRSegmentControlTests */, 89 | C00BF0CF1B92E6C30010A514 /* Products */, 90 | ); 91 | sourceTree = ""; 92 | }; 93 | C00BF0CF1B92E6C30010A514 /* Products */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | C00BF0CE1B92E6C30010A514 /* JRSegmentControl.app */, 97 | C00BF0E71B92E6C30010A514 /* JRSegmentControlTests.xctest */, 98 | ); 99 | name = Products; 100 | sourceTree = ""; 101 | }; 102 | C00BF0D01B92E6C30010A514 /* JRSegmentControl */ = { 103 | isa = PBXGroup; 104 | children = ( 105 | C00BF0FF1B92E7600010A514 /* Classes */, 106 | C00BF0F71B92E71E0010A514 /* JRSegmentControl */, 107 | C00BF0D81B92E6C30010A514 /* ViewController.h */, 108 | C00BF0D91B92E6C30010A514 /* ViewController.m */, 109 | C00BF0D51B92E6C30010A514 /* AppDelegate.h */, 110 | C00BF0D61B92E6C30010A514 /* AppDelegate.m */, 111 | C00BF0DB1B92E6C30010A514 /* Main.storyboard */, 112 | C00BF0DE1B92E6C30010A514 /* Images.xcassets */, 113 | C00BF0E01B92E6C30010A514 /* LaunchScreen.xib */, 114 | C00BF0D11B92E6C30010A514 /* Supporting Files */, 115 | ); 116 | path = JRSegmentControl; 117 | sourceTree = ""; 118 | }; 119 | C00BF0D11B92E6C30010A514 /* Supporting Files */ = { 120 | isa = PBXGroup; 121 | children = ( 122 | C00BF0D21B92E6C30010A514 /* Info.plist */, 123 | C00BF0D31B92E6C30010A514 /* main.m */, 124 | ); 125 | name = "Supporting Files"; 126 | sourceTree = ""; 127 | }; 128 | C00BF0EA1B92E6C30010A514 /* JRSegmentControlTests */ = { 129 | isa = PBXGroup; 130 | children = ( 131 | C00BF0ED1B92E6C30010A514 /* JRSegmentControlTests.m */, 132 | C00BF0EB1B92E6C30010A514 /* Supporting Files */, 133 | ); 134 | path = JRSegmentControlTests; 135 | sourceTree = ""; 136 | }; 137 | C00BF0EB1B92E6C30010A514 /* Supporting Files */ = { 138 | isa = PBXGroup; 139 | children = ( 140 | C00BF0EC1B92E6C30010A514 /* Info.plist */, 141 | ); 142 | name = "Supporting Files"; 143 | sourceTree = ""; 144 | }; 145 | C00BF0F71B92E71E0010A514 /* JRSegmentControl */ = { 146 | isa = PBXGroup; 147 | children = ( 148 | C0B81F5B1C2D482900CBC79A /* JRSegmentControl.h */, 149 | C0B81F5C1C2D482900CBC79A /* JRSegmentControl.m */, 150 | C00BF0FB1B92E74E0010A514 /* JRSegmentViewController.h */, 151 | C00BF0FC1B92E74E0010A514 /* JRSegmentViewController.m */, 152 | ); 153 | path = JRSegmentControl; 154 | sourceTree = ""; 155 | }; 156 | C00BF0FF1B92E7600010A514 /* Classes */ = { 157 | isa = PBXGroup; 158 | children = ( 159 | C00BF1001B92E7790010A514 /* FirstViewController.h */, 160 | C00BF1011B92E7790010A514 /* FirstViewController.m */, 161 | C00BF1021B92E7790010A514 /* FirstViewController.xib */, 162 | C00BF1031B92E7790010A514 /* SecondViewController.h */, 163 | C00BF1041B92E7790010A514 /* SecondViewController.m */, 164 | C00BF1051B92E7790010A514 /* SecondViewController.xib */, 165 | C00BF1061B92E7790010A514 /* ThirdViewController.h */, 166 | C00BF1071B92E7790010A514 /* ThirdViewController.m */, 167 | C00BF1081B92E7790010A514 /* ThirdViewController.xib */, 168 | ); 169 | path = Classes; 170 | sourceTree = ""; 171 | }; 172 | /* End PBXGroup section */ 173 | 174 | /* Begin PBXNativeTarget section */ 175 | C00BF0CD1B92E6C30010A514 /* JRSegmentControl */ = { 176 | isa = PBXNativeTarget; 177 | buildConfigurationList = C00BF0F11B92E6C30010A514 /* Build configuration list for PBXNativeTarget "JRSegmentControl" */; 178 | buildPhases = ( 179 | C00BF0CA1B92E6C30010A514 /* Sources */, 180 | C00BF0CB1B92E6C30010A514 /* Frameworks */, 181 | C00BF0CC1B92E6C30010A514 /* Resources */, 182 | ); 183 | buildRules = ( 184 | ); 185 | dependencies = ( 186 | ); 187 | name = JRSegmentControl; 188 | productName = JRSegmentControl; 189 | productReference = C00BF0CE1B92E6C30010A514 /* JRSegmentControl.app */; 190 | productType = "com.apple.product-type.application"; 191 | }; 192 | C00BF0E61B92E6C30010A514 /* JRSegmentControlTests */ = { 193 | isa = PBXNativeTarget; 194 | buildConfigurationList = C00BF0F41B92E6C30010A514 /* Build configuration list for PBXNativeTarget "JRSegmentControlTests" */; 195 | buildPhases = ( 196 | C00BF0E31B92E6C30010A514 /* Sources */, 197 | C00BF0E41B92E6C30010A514 /* Frameworks */, 198 | C00BF0E51B92E6C30010A514 /* Resources */, 199 | ); 200 | buildRules = ( 201 | ); 202 | dependencies = ( 203 | C00BF0E91B92E6C30010A514 /* PBXTargetDependency */, 204 | ); 205 | name = JRSegmentControlTests; 206 | productName = JRSegmentControlTests; 207 | productReference = C00BF0E71B92E6C30010A514 /* JRSegmentControlTests.xctest */; 208 | productType = "com.apple.product-type.bundle.unit-test"; 209 | }; 210 | /* End PBXNativeTarget section */ 211 | 212 | /* Begin PBXProject section */ 213 | C00BF0C61B92E6C30010A514 /* Project object */ = { 214 | isa = PBXProject; 215 | attributes = { 216 | LastUpgradeCheck = 0640; 217 | ORGANIZATIONNAME = "湛家荣"; 218 | TargetAttributes = { 219 | C00BF0CD1B92E6C30010A514 = { 220 | CreatedOnToolsVersion = 6.4; 221 | }; 222 | C00BF0E61B92E6C30010A514 = { 223 | CreatedOnToolsVersion = 6.4; 224 | TestTargetID = C00BF0CD1B92E6C30010A514; 225 | }; 226 | }; 227 | }; 228 | buildConfigurationList = C00BF0C91B92E6C30010A514 /* Build configuration list for PBXProject "JRSegmentControl" */; 229 | compatibilityVersion = "Xcode 3.2"; 230 | developmentRegion = English; 231 | hasScannedForEncodings = 0; 232 | knownRegions = ( 233 | en, 234 | Base, 235 | ); 236 | mainGroup = C00BF0C51B92E6C30010A514; 237 | productRefGroup = C00BF0CF1B92E6C30010A514 /* Products */; 238 | projectDirPath = ""; 239 | projectRoot = ""; 240 | targets = ( 241 | C00BF0CD1B92E6C30010A514 /* JRSegmentControl */, 242 | C00BF0E61B92E6C30010A514 /* JRSegmentControlTests */, 243 | ); 244 | }; 245 | /* End PBXProject section */ 246 | 247 | /* Begin PBXResourcesBuildPhase section */ 248 | C00BF0CC1B92E6C30010A514 /* Resources */ = { 249 | isa = PBXResourcesBuildPhase; 250 | buildActionMask = 2147483647; 251 | files = ( 252 | C00BF0DD1B92E6C30010A514 /* Main.storyboard in Resources */, 253 | C00BF0E21B92E6C30010A514 /* LaunchScreen.xib in Resources */, 254 | C00BF10E1B92E7790010A514 /* ThirdViewController.xib in Resources */, 255 | C00BF0DF1B92E6C30010A514 /* Images.xcassets in Resources */, 256 | C00BF10A1B92E7790010A514 /* FirstViewController.xib in Resources */, 257 | C00BF10C1B92E7790010A514 /* SecondViewController.xib in Resources */, 258 | ); 259 | runOnlyForDeploymentPostprocessing = 0; 260 | }; 261 | C00BF0E51B92E6C30010A514 /* Resources */ = { 262 | isa = PBXResourcesBuildPhase; 263 | buildActionMask = 2147483647; 264 | files = ( 265 | ); 266 | runOnlyForDeploymentPostprocessing = 0; 267 | }; 268 | /* End PBXResourcesBuildPhase section */ 269 | 270 | /* Begin PBXSourcesBuildPhase section */ 271 | C00BF0CA1B92E6C30010A514 /* Sources */ = { 272 | isa = PBXSourcesBuildPhase; 273 | buildActionMask = 2147483647; 274 | files = ( 275 | C00BF0DA1B92E6C30010A514 /* ViewController.m in Sources */, 276 | C00BF1091B92E7790010A514 /* FirstViewController.m in Sources */, 277 | C00BF10D1B92E7790010A514 /* ThirdViewController.m in Sources */, 278 | C00BF10B1B92E7790010A514 /* SecondViewController.m in Sources */, 279 | C00BF0D71B92E6C30010A514 /* AppDelegate.m in Sources */, 280 | C0B81F5D1C2D482900CBC79A /* JRSegmentControl.m in Sources */, 281 | C00BF0D41B92E6C30010A514 /* main.m in Sources */, 282 | C00BF0FD1B92E74E0010A514 /* JRSegmentViewController.m in Sources */, 283 | ); 284 | runOnlyForDeploymentPostprocessing = 0; 285 | }; 286 | C00BF0E31B92E6C30010A514 /* Sources */ = { 287 | isa = PBXSourcesBuildPhase; 288 | buildActionMask = 2147483647; 289 | files = ( 290 | C00BF0EE1B92E6C30010A514 /* JRSegmentControlTests.m in Sources */, 291 | ); 292 | runOnlyForDeploymentPostprocessing = 0; 293 | }; 294 | /* End PBXSourcesBuildPhase section */ 295 | 296 | /* Begin PBXTargetDependency section */ 297 | C00BF0E91B92E6C30010A514 /* PBXTargetDependency */ = { 298 | isa = PBXTargetDependency; 299 | target = C00BF0CD1B92E6C30010A514 /* JRSegmentControl */; 300 | targetProxy = C00BF0E81B92E6C30010A514 /* PBXContainerItemProxy */; 301 | }; 302 | /* End PBXTargetDependency section */ 303 | 304 | /* Begin PBXVariantGroup section */ 305 | C00BF0DB1B92E6C30010A514 /* Main.storyboard */ = { 306 | isa = PBXVariantGroup; 307 | children = ( 308 | C00BF0DC1B92E6C30010A514 /* Base */, 309 | ); 310 | name = Main.storyboard; 311 | sourceTree = ""; 312 | }; 313 | C00BF0E01B92E6C30010A514 /* LaunchScreen.xib */ = { 314 | isa = PBXVariantGroup; 315 | children = ( 316 | C00BF0E11B92E6C30010A514 /* Base */, 317 | ); 318 | name = LaunchScreen.xib; 319 | sourceTree = ""; 320 | }; 321 | /* End PBXVariantGroup section */ 322 | 323 | /* Begin XCBuildConfiguration section */ 324 | C00BF0EF1B92E6C30010A514 /* Debug */ = { 325 | isa = XCBuildConfiguration; 326 | buildSettings = { 327 | ALWAYS_SEARCH_USER_PATHS = NO; 328 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 329 | CLANG_CXX_LIBRARY = "libc++"; 330 | CLANG_ENABLE_MODULES = YES; 331 | CLANG_ENABLE_OBJC_ARC = YES; 332 | CLANG_WARN_BOOL_CONVERSION = YES; 333 | CLANG_WARN_CONSTANT_CONVERSION = YES; 334 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 335 | CLANG_WARN_EMPTY_BODY = YES; 336 | CLANG_WARN_ENUM_CONVERSION = YES; 337 | CLANG_WARN_INT_CONVERSION = YES; 338 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 339 | CLANG_WARN_UNREACHABLE_CODE = YES; 340 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 341 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 342 | COPY_PHASE_STRIP = NO; 343 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 344 | ENABLE_STRICT_OBJC_MSGSEND = YES; 345 | GCC_C_LANGUAGE_STANDARD = gnu99; 346 | GCC_DYNAMIC_NO_PIC = NO; 347 | GCC_NO_COMMON_BLOCKS = YES; 348 | GCC_OPTIMIZATION_LEVEL = 0; 349 | GCC_PREPROCESSOR_DEFINITIONS = ( 350 | "DEBUG=1", 351 | "$(inherited)", 352 | ); 353 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 354 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 355 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 356 | GCC_WARN_UNDECLARED_SELECTOR = YES; 357 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 358 | GCC_WARN_UNUSED_FUNCTION = YES; 359 | GCC_WARN_UNUSED_VARIABLE = YES; 360 | IPHONEOS_DEPLOYMENT_TARGET = 8.4; 361 | MTL_ENABLE_DEBUG_INFO = YES; 362 | ONLY_ACTIVE_ARCH = YES; 363 | SDKROOT = iphoneos; 364 | TARGETED_DEVICE_FAMILY = "1,2"; 365 | }; 366 | name = Debug; 367 | }; 368 | C00BF0F01B92E6C30010A514 /* Release */ = { 369 | isa = XCBuildConfiguration; 370 | buildSettings = { 371 | ALWAYS_SEARCH_USER_PATHS = NO; 372 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 373 | CLANG_CXX_LIBRARY = "libc++"; 374 | CLANG_ENABLE_MODULES = YES; 375 | CLANG_ENABLE_OBJC_ARC = YES; 376 | CLANG_WARN_BOOL_CONVERSION = YES; 377 | CLANG_WARN_CONSTANT_CONVERSION = YES; 378 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 379 | CLANG_WARN_EMPTY_BODY = YES; 380 | CLANG_WARN_ENUM_CONVERSION = YES; 381 | CLANG_WARN_INT_CONVERSION = YES; 382 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 383 | CLANG_WARN_UNREACHABLE_CODE = YES; 384 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 385 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 386 | COPY_PHASE_STRIP = NO; 387 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 388 | ENABLE_NS_ASSERTIONS = NO; 389 | ENABLE_STRICT_OBJC_MSGSEND = YES; 390 | GCC_C_LANGUAGE_STANDARD = gnu99; 391 | GCC_NO_COMMON_BLOCKS = YES; 392 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 393 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 394 | GCC_WARN_UNDECLARED_SELECTOR = YES; 395 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 396 | GCC_WARN_UNUSED_FUNCTION = YES; 397 | GCC_WARN_UNUSED_VARIABLE = YES; 398 | IPHONEOS_DEPLOYMENT_TARGET = 8.4; 399 | MTL_ENABLE_DEBUG_INFO = NO; 400 | SDKROOT = iphoneos; 401 | TARGETED_DEVICE_FAMILY = "1,2"; 402 | VALIDATE_PRODUCT = YES; 403 | }; 404 | name = Release; 405 | }; 406 | C00BF0F21B92E6C30010A514 /* Debug */ = { 407 | isa = XCBuildConfiguration; 408 | buildSettings = { 409 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 410 | INFOPLIST_FILE = JRSegmentControl/Info.plist; 411 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 412 | PRODUCT_NAME = "$(TARGET_NAME)"; 413 | }; 414 | name = Debug; 415 | }; 416 | C00BF0F31B92E6C30010A514 /* Release */ = { 417 | isa = XCBuildConfiguration; 418 | buildSettings = { 419 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 420 | INFOPLIST_FILE = JRSegmentControl/Info.plist; 421 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 422 | PRODUCT_NAME = "$(TARGET_NAME)"; 423 | }; 424 | name = Release; 425 | }; 426 | C00BF0F51B92E6C30010A514 /* Debug */ = { 427 | isa = XCBuildConfiguration; 428 | buildSettings = { 429 | BUNDLE_LOADER = "$(TEST_HOST)"; 430 | FRAMEWORK_SEARCH_PATHS = ( 431 | "$(SDKROOT)/Developer/Library/Frameworks", 432 | "$(inherited)", 433 | ); 434 | GCC_PREPROCESSOR_DEFINITIONS = ( 435 | "DEBUG=1", 436 | "$(inherited)", 437 | ); 438 | INFOPLIST_FILE = JRSegmentControlTests/Info.plist; 439 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 440 | PRODUCT_NAME = "$(TARGET_NAME)"; 441 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/JRSegmentControl.app/JRSegmentControl"; 442 | }; 443 | name = Debug; 444 | }; 445 | C00BF0F61B92E6C30010A514 /* Release */ = { 446 | isa = XCBuildConfiguration; 447 | buildSettings = { 448 | BUNDLE_LOADER = "$(TEST_HOST)"; 449 | FRAMEWORK_SEARCH_PATHS = ( 450 | "$(SDKROOT)/Developer/Library/Frameworks", 451 | "$(inherited)", 452 | ); 453 | INFOPLIST_FILE = JRSegmentControlTests/Info.plist; 454 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 455 | PRODUCT_NAME = "$(TARGET_NAME)"; 456 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/JRSegmentControl.app/JRSegmentControl"; 457 | }; 458 | name = Release; 459 | }; 460 | /* End XCBuildConfiguration section */ 461 | 462 | /* Begin XCConfigurationList section */ 463 | C00BF0C91B92E6C30010A514 /* Build configuration list for PBXProject "JRSegmentControl" */ = { 464 | isa = XCConfigurationList; 465 | buildConfigurations = ( 466 | C00BF0EF1B92E6C30010A514 /* Debug */, 467 | C00BF0F01B92E6C30010A514 /* Release */, 468 | ); 469 | defaultConfigurationIsVisible = 0; 470 | defaultConfigurationName = Release; 471 | }; 472 | C00BF0F11B92E6C30010A514 /* Build configuration list for PBXNativeTarget "JRSegmentControl" */ = { 473 | isa = XCConfigurationList; 474 | buildConfigurations = ( 475 | C00BF0F21B92E6C30010A514 /* Debug */, 476 | C00BF0F31B92E6C30010A514 /* Release */, 477 | ); 478 | defaultConfigurationIsVisible = 0; 479 | defaultConfigurationName = Release; 480 | }; 481 | C00BF0F41B92E6C30010A514 /* Build configuration list for PBXNativeTarget "JRSegmentControlTests" */ = { 482 | isa = XCConfigurationList; 483 | buildConfigurations = ( 484 | C00BF0F51B92E6C30010A514 /* Debug */, 485 | C00BF0F61B92E6C30010A514 /* Release */, 486 | ); 487 | defaultConfigurationIsVisible = 0; 488 | defaultConfigurationName = Release; 489 | }; 490 | /* End XCConfigurationList section */ 491 | }; 492 | rootObject = C00BF0C61B92E6C30010A514 /* Project object */; 493 | } 494 | -------------------------------------------------------------------------------- /JRSegmentControl.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /JRSegmentControl.xcodeproj/project.xcworkspace/xcshareddata/JRSegmentControl.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | 8B6A52A0-CAD8-4780-8A24-0C6EB6C7A133 9 | IDESourceControlProjectName 10 | JRSegmentControl 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 65C410731B10644913A67FB8EC36D0AA7F7E81C8 14 | https://github.com/zhanjiarong/JRSegmentControl.git 15 | 16 | IDESourceControlProjectPath 17 | JRSegmentControl.xcodeproj 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | 65C410731B10644913A67FB8EC36D0AA7F7E81C8 21 | ../.. 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/zhanjiarong/JRSegmentControl.git 25 | IDESourceControlProjectVersion 26 | 111 27 | IDESourceControlProjectWCCIdentifier 28 | 65C410731B10644913A67FB8EC36D0AA7F7E81C8 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | 65C410731B10644913A67FB8EC36D0AA7F7E81C8 36 | IDESourceControlWCCName 37 | JRSegmentControl 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /JRSegmentControl.xcodeproj/project.xcworkspace/xcuserdata/zhanjiarong.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhanjiarong/JRSegmentControl/59da21e85d023b38cde98d8a35d4b813abeb0d62/JRSegmentControl.xcodeproj/project.xcworkspace/xcuserdata/zhanjiarong.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /JRSegmentControl.xcodeproj/xcuserdata/zhanjiarong.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /JRSegmentControl.xcodeproj/xcuserdata/zhanjiarong.xcuserdatad/xcschemes/JRSegmentControl.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 77 | 83 | 84 | 85 | 86 | 87 | 88 | 94 | 96 | 102 | 103 | 104 | 105 | 107 | 108 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /JRSegmentControl.xcodeproj/xcuserdata/zhanjiarong.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | JRSegmentControl.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | C00BF0CD1B92E6C30010A514 16 | 17 | primary 18 | 19 | 20 | C00BF0E61B92E6C30010A514 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /JRSegmentControl/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // JRSegmentControl 4 | // 5 | // Created by 湛家荣 on 15/8/30. 6 | // Copyright (c) 2015年 湛家荣. 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 | -------------------------------------------------------------------------------- /JRSegmentControl/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // JRSegmentControl 4 | // 5 | // Created by 湛家荣 on 15/8/30. 6 | // Copyright (c) 2015年 湛家荣. 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 | 21 | [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:30.0f/255 green:95.0f/255 blue:185.0f/255 alpha:1.0f]]; 22 | [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; 23 | 24 | return YES; 25 | } 26 | 27 | - (void)applicationWillResignActive:(UIApplication *)application { 28 | // 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. 29 | // 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. 30 | } 31 | 32 | - (void)applicationDidEnterBackground:(UIApplication *)application { 33 | // 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. 34 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 35 | } 36 | 37 | - (void)applicationWillEnterForeground:(UIApplication *)application { 38 | // 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. 39 | } 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // 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. 43 | } 44 | 45 | - (void)applicationWillTerminate:(UIApplication *)application { 46 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /JRSegmentControl/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /JRSegmentControl/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /JRSegmentControl/Classes/FirstViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // FirstViewController.h 3 | // MaoYan 4 | // 5 | // Created by 湛家荣 on 15/8/29. 6 | // Copyright (c) 2015年 湛家荣. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface FirstViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /JRSegmentControl/Classes/FirstViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // FirstViewController.m 3 | // MaoYan 4 | // 5 | // Created by 湛家荣 on 15/8/29. 6 | // Copyright (c) 2015年 湛家荣. All rights reserved. 7 | // 8 | 9 | #import "FirstViewController.h" 10 | 11 | @interface FirstViewController () 12 | 13 | @end 14 | 15 | @implementation FirstViewController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | 20 | 21 | } 22 | 23 | - (void)didReceiveMemoryWarning { 24 | [super didReceiveMemoryWarning]; 25 | // Dispose of any resources that can be recreated. 26 | } 27 | 28 | 29 | #pragma mark - UITableViewDataSource, UITableViewDelegate 30 | 31 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 32 | { 33 | return 20; 34 | } 35 | 36 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 37 | { 38 | static NSString *cellID = @"firstVCCell"; 39 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; 40 | 41 | if (cell == nil) { 42 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; 43 | 44 | cell.showsReorderControl = YES; 45 | cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 46 | } 47 | 48 | cell.indentationLevel = indexPath.row; 49 | cell.textLabel.text = @"这是一个cell"; 50 | 51 | return cell; 52 | } 53 | 54 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 55 | { 56 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; 57 | } 58 | 59 | 60 | @end 61 | -------------------------------------------------------------------------------- /JRSegmentControl/Classes/FirstViewController.xib: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /JRSegmentControl/Classes/SecondViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // SecondViewController.h 3 | // MaoYan 4 | // 5 | // Created by 湛家荣 on 15/8/29. 6 | // Copyright (c) 2015年 湛家荣. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SecondViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /JRSegmentControl/Classes/SecondViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // SecondViewController.m 3 | // MaoYan 4 | // 5 | // Created by 湛家荣 on 15/8/29. 6 | // Copyright (c) 2015年 湛家荣. All rights reserved. 7 | // 8 | 9 | #import "SecondViewController.h" 10 | 11 | @interface SecondViewController () 12 | 13 | @end 14 | 15 | @implementation SecondViewController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | // Do any additional setup after loading the view from its nib. 20 | } 21 | 22 | - (void)didReceiveMemoryWarning { 23 | [super didReceiveMemoryWarning]; 24 | // Dispose of any resources that can be recreated. 25 | } 26 | 27 | /* 28 | #pragma mark - Navigation 29 | 30 | // In a storyboard-based application, you will often want to do a little preparation before navigation 31 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 32 | // Get the new view controller using [segue destinationViewController]. 33 | // Pass the selected object to the new view controller. 34 | } 35 | */ 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /JRSegmentControl/Classes/SecondViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /JRSegmentControl/Classes/ThirdViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ThirdViewController.h 3 | // MaoYan 4 | // 5 | // Created by 湛家荣 on 15/8/29. 6 | // Copyright (c) 2015年 湛家荣. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ThirdViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /JRSegmentControl/Classes/ThirdViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ThirdViewController.m 3 | // MaoYan 4 | // 5 | // Created by 湛家荣 on 15/8/29. 6 | // Copyright (c) 2015年 湛家荣. All rights reserved. 7 | // 8 | 9 | #import "ThirdViewController.h" 10 | 11 | @interface ThirdViewController () 12 | 13 | @end 14 | 15 | @implementation ThirdViewController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | // Do any additional setup after loading the view from its nib. 20 | } 21 | 22 | - (void)didReceiveMemoryWarning { 23 | [super didReceiveMemoryWarning]; 24 | // Dispose of any resources that can be recreated. 25 | } 26 | 27 | /* 28 | #pragma mark - Navigation 29 | 30 | // In a storyboard-based application, you will often want to do a little preparation before navigation 31 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 32 | // Get the new view controller using [segue destinationViewController]. 33 | // Pass the selected object to the new view controller. 34 | } 35 | */ 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /JRSegmentControl/Classes/ThirdViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /JRSegmentControl/Images.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 | } -------------------------------------------------------------------------------- /JRSegmentControl/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.zhanjr.$(PRODUCT_NAME:rfc1034identifier) 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 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /JRSegmentControl/JRSegmentControl/JRSegmentControl.h: -------------------------------------------------------------------------------- 1 | // 2 | // JRSegmentControl.h 3 | // JRSegmentControl 4 | // 5 | // Created by 湛家荣 on 15/8/29. 6 | // Copyright (c) 2015年 湛家荣. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class JRSegmentControl; 12 | 13 | #pragma mark - JRSegmentButton 14 | @interface JRSegmentButton : UIButton 15 | 16 | @end 17 | 18 | 19 | #pragma mark - JRSegmentControlDelegate 20 | @protocol JRSegmentControlDelegate 21 | 22 | /** 选中某个按钮时的代理回调 */ 23 | - (void)segmentControl:(JRSegmentControl *)segment didSelectedIndex:(NSInteger)index; 24 | 25 | @optional 26 | 27 | /** 指示视图滑动进度的代理回调 */ 28 | - (void)segmentControl:(JRSegmentControl *)segment didScrolledPersent:(CGFloat)persent; 29 | 30 | @end 31 | 32 | #pragma mark - JRSegmentControl 33 | @interface JRSegmentControl : UIView 34 | 35 | /** 36 | * 按钮标题数组 37 | */ 38 | @property (nonatomic, copy) NSArray *titles; 39 | /** 按钮圆角半径 */ 40 | @property (nonatomic, assign) CGFloat cornerRadius; 41 | /** 指示视图的颜色 */ 42 | @property (nonatomic, strong) UIColor *indicatorViewColor; 43 | /** 未选中时的按钮文字颜色 */ 44 | @property (nonatomic, strong) UIColor *titleColor; 45 | 46 | @property (nonatomic, weak) id delegate; 47 | 48 | /** 设置segment的索引为index的按钮处于选中状态 */ 49 | - (void)setSelectedIndex:(NSInteger)index; 50 | 51 | - (void)setIndicatorViewPercent:(CGFloat)percent; 52 | 53 | /** 选开始的设置,指示视图变暗,字体颜色改变 */ 54 | - (void)selectedBegan; 55 | 56 | /** 选开始的设置 */ 57 | - (void)selectedEnd; 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /JRSegmentControl/JRSegmentControl/JRSegmentControl.m: -------------------------------------------------------------------------------- 1 | // 2 | // JRSegmentControl.m 3 | // JRSegmentControl 4 | // 5 | // Created by 湛家荣 on 15/8/29. 6 | // Copyright (c) 2015年 湛家荣. All rights reserved. 7 | // 8 | 9 | #import "JRSegmentControl.h" 10 | 11 | #define DefaultCurrentBtnColor [UIColor whiteColor] 12 | 13 | 14 | #pragma mark - JRSegmentButton 15 | 16 | @interface JRSegmentButton () 17 | 18 | @end 19 | 20 | @implementation JRSegmentButton 21 | 22 | - (void)setHighlighted:(BOOL)highlighted { 23 | // 取消高亮效果 24 | } 25 | 26 | @end 27 | 28 | #pragma mark - JRSegmentControl 29 | 30 | @interface JRSegmentControl () 31 | { 32 | NSUInteger _btnCount; // 按钮总数 33 | 34 | CGFloat _btnWidth; // 按钮宽度 35 | 36 | JRSegmentButton *_currentBtn; // 指示视图当前所在的按钮 37 | 38 | UIView *_indicatorView; // 指示视图(滑动视图) 39 | 40 | BOOL _isSelectedBegan; // 是否设置了selectedBegan 41 | } 42 | 43 | @property (nonatomic, strong) NSMutableArray *buttons; // 存放button 44 | 45 | @end 46 | 47 | 48 | 49 | @implementation JRSegmentControl 50 | 51 | @synthesize indicatorViewColor = _indicatorViewColor; 52 | 53 | 54 | #pragma mark 初始化 55 | - (instancetype)initWithFrame:(CGRect)frame 56 | { 57 | if (self = [super initWithFrame:frame]) { 58 | self.layer.cornerRadius = frame.size.height / 10; 59 | self.layer.masksToBounds = YES; 60 | } 61 | 62 | return self; 63 | } 64 | 65 | #pragma mark setter/getter方法 66 | 67 | /** 68 | * 设置按钮标题数组 69 | */ 70 | - (void)setTitles:(NSArray *)titles 71 | { 72 | _titles = [titles copy]; 73 | 74 | _btnCount = [_titles count]; 75 | 76 | [self createUI]; 77 | } 78 | 79 | /** 80 | * 设置圆角半径 81 | */ 82 | - (void)setCornerRadius:(CGFloat)cornerRadius 83 | { 84 | _cornerRadius = cornerRadius; 85 | 86 | self.layer.cornerRadius = _cornerRadius; 87 | _indicatorView.layer.cornerRadius = _cornerRadius; 88 | } 89 | 90 | /** 91 | * 设置保存按钮的数组 92 | */ 93 | - (NSMutableArray *)buttons 94 | { 95 | if (_buttons == nil) { 96 | _buttons = [NSMutableArray array]; 97 | } 98 | return _buttons; 99 | } 100 | 101 | /** 102 | * 设置指示视图的背景色 103 | */ 104 | - (void)setIndicatorViewColor:(UIColor *)indicatorViewColor 105 | { 106 | if (indicatorViewColor == nil) { 107 | return; 108 | } 109 | _indicatorViewColor = indicatorViewColor; 110 | _indicatorView.backgroundColor = _indicatorViewColor; 111 | } 112 | 113 | /** 114 | * 获取指示视图的背景色 115 | */ 116 | - (UIColor *)indicatorViewColor 117 | { 118 | if (_indicatorViewColor == nil) { 119 | _indicatorViewColor = [UIColor whiteColor]; 120 | } 121 | return _indicatorViewColor; 122 | } 123 | 124 | /** 125 | * 设置按钮上文字颜色 126 | */ 127 | - (void)setTitleColor:(UIColor *)titleColor { 128 | _titleColor = titleColor; 129 | 130 | for (int i = 0; i < _btnCount; i++) { 131 | JRSegmentButton *btn = self.buttons[i]; 132 | [btn setTitleColor:_titleColor forState:UIControlStateNormal]; 133 | [btn setTitleColor:_titleColor forState:UIControlStateHighlighted]; 134 | } 135 | 136 | // 如果不设置backgroundColor,第一个按钮的文字颜色就会被设置为默认颜色 137 | [_currentBtn setTitleColor:DefaultCurrentBtnColor forState:UIControlStateNormal]; 138 | } 139 | 140 | /** 141 | * 设置背景色 142 | */ 143 | - (void)setBackgroundColor:(UIColor *)backgroundColor 144 | { 145 | [super setBackgroundColor:backgroundColor]; 146 | [_currentBtn setTitleColor:backgroundColor forState:UIControlStateNormal]; 147 | } 148 | 149 | 150 | #pragma mark 创建视图 151 | - (void)createUI 152 | { 153 | _btnWidth = self.frame.size.width / _btnCount; 154 | CGFloat btnHeight = self.frame.size.height; 155 | 156 | // 指示视图 157 | _indicatorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _btnWidth, btnHeight)]; 158 | _indicatorView.backgroundColor = self.indicatorViewColor; 159 | _indicatorView.layer.cornerRadius = self.layer.cornerRadius; 160 | _indicatorView.layer.masksToBounds = YES; 161 | [self addSubview:_indicatorView]; 162 | 163 | // 创建各个按钮 164 | for (int i = 0; i < _btnCount; i++) 165 | { 166 | JRSegmentButton *btn = [JRSegmentButton buttonWithType:UIButtonTypeSystem]; 167 | btn.frame = CGRectMake(_btnWidth * i, 0, _btnWidth, btnHeight); 168 | [btn setTitle:self.titles[i] forState:UIControlStateNormal]; 169 | btn.titleLabel.font = [UIFont boldSystemFontOfSize:17.0f]; 170 | [btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside]; 171 | 172 | [self addSubview:btn]; 173 | 174 | [self.buttons addObject:btn]; // 加入数组 175 | } 176 | 177 | // 第一个设置字体颜色 178 | _currentBtn = (JRSegmentButton *)self.buttons[0]; 179 | // 如果不设置backgroundColor,第一个按钮的文字颜色就会被设置为默认颜色 180 | [_currentBtn setTitleColor:DefaultCurrentBtnColor forState:UIControlStateNormal]; 181 | } 182 | 183 | #pragma mark 事件拦截,当点击区域在指示视图的范围内时就直接把事件交给self处理,按钮就接收不到事件了 184 | - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event 185 | { 186 | CGPoint p = [self convertPoint:point toView:_indicatorView]; 187 | if ([_indicatorView pointInside:p withEvent:event]) { 188 | return self; 189 | } else { 190 | return [super hitTest:point withEvent:event]; 191 | } 192 | } 193 | 194 | #pragma mark self的触摸事件处理 195 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 196 | { 197 | [self selectedBegan]; ////////////////////////////////////// 198 | } 199 | 200 | - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 201 | { 202 | UITouch *touch = [touches anyObject]; 203 | CGPoint point = [touch locationInView:self]; 204 | CGPoint prevP = [touch previousLocationInView:self]; 205 | 206 | CGFloat delta = point.x - prevP.x; // 手势改变的x范围 207 | 208 | CGRect frame = _indicatorView.frame; 209 | 210 | // 限制_indicatorView的滑动范围 211 | if (frame.origin.x + delta >= 0 && frame.origin.x + delta <= (_btnCount - 1) * _btnWidth) { 212 | frame.origin = CGPointMake(frame.origin.x + delta, 0); 213 | } 214 | 215 | CGFloat persent = _indicatorView.frame.origin.x / (_btnCount * _btnWidth); 216 | if ([self.delegate respondsToSelector:@selector(segmentControl:didScrolledPersent:)]) { 217 | [self.delegate segmentControl:self didScrolledPersent:persent]; 218 | } 219 | 220 | _indicatorView.frame = frame; 221 | } 222 | 223 | - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 224 | { 225 | // 先计算_indicatorView最终应该在哪个button上 226 | CGPoint center = _indicatorView.center; 227 | 228 | NSInteger index = (NSInteger)center.x / _btnWidth; 229 | 230 | [self setSelectedIndex:index]; ////////////////////////////////////// 231 | } 232 | 233 | - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event 234 | { 235 | [self touchesEnded:touches withEvent:event]; 236 | } 237 | 238 | 239 | - (void)setIndicatorViewPercent:(CGFloat)percent { 240 | CGRect frame = _indicatorView.frame; 241 | frame.origin.x = _btnCount * _btnWidth * percent; 242 | 243 | _indicatorView.frame = frame; 244 | } 245 | 246 | #pragma mark 按钮点击事件处理 247 | - (void)btnClicked:(UIButton *)btn 248 | { 249 | NSInteger index = 0; 250 | for (UIButton *button in self.buttons) { 251 | if (button.frame.origin.x == btn.frame.origin.x) { 252 | break; 253 | } 254 | index++; 255 | } 256 | 257 | [self setSelectedIndex:index]; ////////////////////////////////////// 258 | } 259 | 260 | #pragma mark 设置选中按钮 261 | - (void)setSelectedIndex:(NSInteger)index 262 | { 263 | // 告诉代理选中了哪个按钮 264 | if ([self.delegate respondsToSelector:@selector(segmentControl:didSelectedIndex:)]) { 265 | [self.delegate segmentControl:self didSelectedIndex:index]; 266 | } 267 | 268 | [self selectedBegan]; // 选中开始的设置 ////////////////////////////////////// 269 | 270 | _currentBtn = self.buttons[index]; 271 | 272 | [UIView animateWithDuration:0.25f animations:^{ 273 | 274 | _indicatorView.frame = CGRectMake(_btnWidth * index, 0, _indicatorView.frame.size.width, _indicatorView.frame.size.height); 275 | 276 | } completion:^(BOOL finished) { 277 | 278 | [self selectedEnd]; // 选中结束的设置 ////////////////////////////////////// 279 | }]; 280 | } 281 | 282 | /** 选开始的设置,指示视图变暗,字体颜色改变 */ 283 | - (void)selectedBegan 284 | { 285 | if (_isSelectedBegan) return; 286 | 287 | _isSelectedBegan = YES; 288 | 289 | _indicatorView.alpha = 0.5f; 290 | [_currentBtn setTitleColor:self.titleColor forState:UIControlStateNormal]; 291 | } 292 | 293 | /** 选开始的设置 */ 294 | - (void)selectedEnd 295 | { 296 | if (!_isSelectedBegan) return; 297 | 298 | _isSelectedBegan = NO; 299 | 300 | _indicatorView.alpha = 1.0f; 301 | 302 | // 如果没有设置background,就为默认颜色 303 | UIColor *color = self.backgroundColor ? self.backgroundColor : DefaultCurrentBtnColor; 304 | [_currentBtn setTitleColor:color forState:UIControlStateNormal]; 305 | } 306 | 307 | @end 308 | -------------------------------------------------------------------------------- /JRSegmentControl/JRSegmentControl/JRSegmentViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // JRSegmentViewController.h 3 | // JRSegmentControl 4 | // 5 | // Created by 湛家荣 on 15/8/29. 6 | // Copyright (c) 2015年 湛家荣. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "JRSegmentControl.h" 11 | 12 | @interface JRSegmentViewController : UIViewController 13 | 14 | @property (nonatomic, copy) NSArray *viewControllers; 15 | @property (nonatomic, copy) NSArray *titles; 16 | 17 | /** 指示视图的颜色 */ 18 | @property (nonatomic, strong) UIColor *indicatorViewColor; 19 | /** segment的背景颜色 */ 20 | @property (nonatomic, strong) UIColor *segmentBgColor; 21 | /** 22 | * segment每一项的文字颜色 23 | */ 24 | @property (nonatomic, strong) UIColor *titleColor; 25 | /** segment每一项的宽 */ 26 | @property (nonatomic, assign) CGFloat itemWidth; 27 | /** segment每一项的高 */ 28 | @property (nonatomic, assign) CGFloat itemHeight; 29 | 30 | @end 31 | 32 | -------------------------------------------------------------------------------- /JRSegmentControl/JRSegmentControl/JRSegmentViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // JRSegmentViewController.m 3 | // JRSegmentControl 4 | // 5 | // Created by 湛家荣 on 15/8/29. 6 | // Copyright (c) 2015年 湛家荣. All rights reserved. 7 | // 8 | 9 | #import "JRSegmentViewController.h" 10 | 11 | @interface JRSegmentViewController () 12 | { 13 | CGFloat vcWidth; // 每个子视图控制器的视图的宽 14 | CGFloat vcHeight; // 每个子视图控制器的视图的高 15 | 16 | JRSegmentControl *segment; 17 | 18 | BOOL _isDrag; 19 | } 20 | 21 | @property (nonatomic, strong) UIScrollView *scrollView; 22 | 23 | @end 24 | 25 | @implementation JRSegmentViewController 26 | 27 | - (void)viewDidLoad { 28 | [super viewDidLoad]; 29 | self.view.backgroundColor = [UIColor whiteColor]; 30 | 31 | 32 | [self setupScrollView]; 33 | [self setupViewControllers]; 34 | [self setupSegmentControl]; 35 | 36 | } 37 | 38 | - (void)didReceiveMemoryWarning { 39 | [super didReceiveMemoryWarning]; 40 | // Dispose of any resources that can be recreated. 41 | } 42 | 43 | 44 | - (CGFloat)itemWidth 45 | { 46 | if (_itemWidth == 0) { 47 | _itemWidth = 60.0f; 48 | } 49 | return _itemWidth; 50 | } 51 | 52 | - (CGFloat)itemHeight 53 | { 54 | if (_itemHeight == 0) { 55 | _itemHeight = 30.0f; 56 | } 57 | return _itemHeight; 58 | } 59 | 60 | - (BOOL)shouldAutorotate 61 | { 62 | return NO; 63 | } 64 | 65 | - (NSUInteger)supportedInterfaceOrientations 66 | { 67 | return UIInterfaceOrientationMaskPortrait; 68 | } 69 | 70 | - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 71 | { 72 | return UIInterfaceOrientationPortrait; 73 | } 74 | 75 | /** 设置scrollView */ 76 | - (void)setupScrollView 77 | { 78 | CGFloat Y = 0.0f; 79 | if (self.navigationController != nil && ![self.navigationController isNavigationBarHidden]) { 80 | self.automaticallyAdjustsScrollViewInsets = NO; 81 | Y = 64.0f; 82 | } 83 | 84 | vcWidth = self.view.frame.size.width; 85 | vcHeight = self.view.frame.size.height - Y; 86 | 87 | UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f, Y, vcWidth, vcHeight)]; 88 | scrollView.contentSize = CGSizeMake(vcWidth * self.viewControllers.count, vcHeight); 89 | scrollView.showsHorizontalScrollIndicator = NO; 90 | scrollView.showsVerticalScrollIndicator = NO; 91 | scrollView.pagingEnabled = YES; 92 | scrollView.delegate = self; 93 | [self.view addSubview:scrollView]; 94 | self.scrollView = scrollView; 95 | } 96 | 97 | /** 设置子视图控制器,这个方法必须在viewDidLoad方法里执行,否则子视图控制器各项属性为空 */ 98 | - (void)setupViewControllers 99 | { 100 | int cnt = (int)self.viewControllers.count; 101 | for (int i = 0; i < cnt; i++) { 102 | UIViewController *vc = self.viewControllers[i]; 103 | [self addChildViewController:vc]; 104 | 105 | vc.view.frame = CGRectMake(vcWidth * i, 0, vcWidth, vcHeight); 106 | [self.scrollView addSubview:vc.view]; 107 | } 108 | } 109 | 110 | /** 设置segment */ 111 | - (void)setupSegmentControl 112 | { 113 | _itemWidth = 60.0f; 114 | // 设置titleView 115 | segment = [[JRSegmentControl alloc] initWithFrame:CGRectMake(0, 0, _itemWidth * 3, 30.0f)]; 116 | segment.titles = self.titles; 117 | segment.cornerRadius = 5.0f; 118 | segment.titleColor = self.titleColor; 119 | segment.indicatorViewColor = self.indicatorViewColor; 120 | segment.backgroundColor = self.segmentBgColor; 121 | 122 | segment.delegate = self; 123 | self.navigationItem.titleView = segment; 124 | } 125 | 126 | 127 | #pragma mark - UIScrollViewDelegate 128 | 129 | - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { 130 | [segment selectedBegan]; 131 | _isDrag = YES; 132 | } 133 | 134 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView { 135 | 136 | if (_isDrag) { 137 | CGFloat percent = scrollView.contentOffset.x / scrollView.contentSize.width; 138 | 139 | [segment setIndicatorViewPercent:percent]; 140 | } 141 | } 142 | 143 | - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { 144 | if (decelerate == NO) { 145 | [segment selectedEnd]; 146 | } 147 | } 148 | 149 | - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { 150 | NSInteger index = scrollView.contentOffset.x / scrollView.frame.size.width; 151 | [segment setSelectedIndex:index]; 152 | _isDrag = NO; 153 | } 154 | 155 | #pragma mark - JRSegmentControlDelegate 156 | 157 | - (void)segmentControl:(JRSegmentControl *)segment didSelectedIndex:(NSInteger)index { 158 | CGFloat X = index * self.view.frame.size.width; 159 | [self.scrollView setContentOffset:CGPointMake(X, 0) animated:YES]; 160 | } 161 | 162 | @end 163 | -------------------------------------------------------------------------------- /JRSegmentControl/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // JRSegmentControl 4 | // 5 | // Created by 湛家荣 on 15/8/30. 6 | // Copyright (c) 2015年 湛家荣. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /JRSegmentControl/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // JRSegmentControl 4 | // 5 | // Created by 湛家荣 on 15/8/30. 6 | // Copyright (c) 2015年 湛家荣. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | #import "JRSegmentViewController.h" 12 | 13 | #import "FirstViewController.h" 14 | #import "SecondViewController.h" 15 | #import "ThirdViewController.h" 16 | 17 | @interface ViewController () 18 | 19 | @end 20 | 21 | @implementation ViewController 22 | 23 | - (void)viewDidLoad { 24 | [super viewDidLoad]; 25 | // Do any additional setup after loading the view, typically from a nib. 26 | } 27 | 28 | - (void)didReceiveMemoryWarning { 29 | [super didReceiveMemoryWarning]; 30 | // Dispose of any resources that can be recreated. 31 | } 32 | 33 | - (IBAction)btnClicked:(UIButton *)sender 34 | { 35 | FirstViewController *firstVC = [[FirstViewController alloc] init]; 36 | SecondViewController *secondVC = [[SecondViewController alloc] init]; 37 | ThirdViewController *thirdVC = [[ThirdViewController alloc] init]; 38 | 39 | // ... 40 | JRSegmentViewController *vc = [[JRSegmentViewController alloc] init]; 41 | vc.segmentBgColor = [UIColor colorWithRed:18.0f/255 green:50.0f/255 blue:110.0f/255 alpha:1.0f]; 42 | vc.indicatorViewColor = [UIColor whiteColor]; 43 | vc.titleColor = [UIColor whiteColor]; 44 | 45 | [vc setViewControllers:@[firstVC, secondVC, thirdVC]]; 46 | [vc setTitles:@[@"热点", @"聚焦", @"推荐"]]; 47 | 48 | [self.navigationController pushViewController:vc animated:YES]; 49 | } 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /JRSegmentControl/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // JRSegmentControl 4 | // 5 | // Created by 湛家荣 on 15/8/30. 6 | // Copyright (c) 2015年 湛家荣. 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 | -------------------------------------------------------------------------------- /JRSegmentControlTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.zhanjr.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /JRSegmentControlTests/JRSegmentControlTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // JRSegmentControlTests.m 3 | // JRSegmentControlTests 4 | // 5 | // Created by 湛家荣 on 15/8/30. 6 | // Copyright (c) 2015年 湛家荣. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface JRSegmentControlTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation JRSegmentControlTests 17 | 18 | - (void)setUp { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | [super tearDown]; 26 | } 27 | 28 | - (void)testExample { 29 | // This is an example of a functional test case. 30 | XCTAssert(YES, @"Pass"); 31 | } 32 | 33 | - (void)testPerformanceExample { 34 | // This is an example of a performance test case. 35 | [self measureBlock:^{ 36 | // Put the code you want to measure the time of here. 37 | }]; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JRSegmentControl 2 | 3 | 4 | 一个类似于**UISegmentControl**的自定义控制,可以点击和滑动来切换不同的选项。同时封装了**JRSegmentViewController**可以方便集成类似于《猫眼电影》中的切换效果。 5 | 6 | ------------- 7 | 8 | ![JRSegmentControl](https://github.com/zhanjiarong/JRSegmentControl/blob/master/2015-08-30_16_49_40.gif?raw=true) 9 | 10 | ------------- 11 | 12 | ## 使用方法 13 | 14 | ##### (一) 15 | 16 | ``` 17 | #import "JRSegmentViewController.h" 18 | ``` 19 | 20 | 初始化视图控制器,并设置viewControllers属性,如: 21 | 22 | ``` 23 | JRSegmentViewController *vc = [[JRSegmentViewController alloc] init]; 24 | vc.segmentBgColor = [UIColor colorWithRed:18.0f/255 green:50.0f/255 blue:110.0f/255 alpha:1.0f]; 25 | vc.indicatorViewColor = [UIColor whiteColor]; 26 | vc.titleColor = [UIColor whiteColor]; 27 | 28 | [vc setViewControllers:@[firstVC, secondVC, thirdVC]]; 29 | [vc setTitles:@[@"热点", @"聚焦", @"推荐"]]; 30 | 31 | [self.navigationController pushViewController:vc animated:YES]; 32 | ``` 33 | 34 | 以上方法可以实现Demo中的效果,可参考Demo。 35 | 36 | 37 | ##### (二) 38 | 39 | 单独使用 **JRSegmentControl**,使用方法类似 **UISegmentControl** 40 | 41 | ``` 42 | #import "JRSegmentControl" 43 | ``` 44 | 45 | ``` 46 | JRSegmentControl *segment = [[JRSegmentControl alloc] initWithFrame:CGRectMake(0, 0, _itemWidth * 3, 30.0f)]; 47 | segment.titles = @[@"热点", @"聚焦", @"推荐"]; 48 | segment.cornerRadius = 5.0f; 49 | segment.titleColor = [UIColor whiteColor]; 50 | segment.indicatorViewColor = [UIColor whiteColor]; 51 | segment.backgroundColor = [UIColor colorWithRed:18.0f/255 green:50.0f/255 blue:110.0f/255 alpha:1.0f]; 52 | 53 | segment.delegate = self; // 遵守协议即可 54 | 55 | [self.view addSubView:segment]; 56 | 57 | ``` --------------------------------------------------------------------------------