├── .gitignore ├── HMSegmentedControl.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── HMSegmentedControl ├── HMSegmentedControl.h ├── HMSegmentedControl.swift └── Info.plist ├── HMSegmentedControlExample ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist └── ViewController.swift ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | ## Playgrounds 31 | timeline.xctimeline 32 | playground.xcworkspace 33 | 34 | # Swift Package Manager 35 | # 36 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 37 | # Packages/ 38 | .build/ 39 | 40 | # CocoaPods 41 | # 42 | # We recommend against adding the Pods directory to your .gitignore. However 43 | # you should judge for yourself, the pros and cons are mentioned at: 44 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 45 | # 46 | # Pods/ 47 | 48 | # Carthage 49 | # 50 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 51 | # Carthage/Checkouts 52 | 53 | Carthage/Build 54 | 55 | # fastlane 56 | # 57 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 58 | # screenshots whenever they are needed. 59 | # For more information about the recommended setup visit: 60 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 61 | 62 | fastlane/report.xml 63 | fastlane/Preview.html 64 | fastlane/screenshots 65 | fastlane/test_output 66 | -------------------------------------------------------------------------------- /HMSegmentedControl.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 5437C93F1D6D885D00F0A2F7 /* HMSegmentedControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5437C93E1D6D885D00F0A2F7 /* HMSegmentedControl.swift */; }; 11 | 549B5BCA1DCF41FD009F91E5 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 549B5BC21DCF41FD009F91E5 /* AppDelegate.swift */; }; 12 | 549B5BCB1DCF41FD009F91E5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 549B5BC31DCF41FD009F91E5 /* Assets.xcassets */; }; 13 | 549B5BCC1DCF41FD009F91E5 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 549B5BC41DCF41FD009F91E5 /* LaunchScreen.storyboard */; }; 14 | 549B5BCD1DCF41FD009F91E5 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 549B5BC61DCF41FD009F91E5 /* Main.storyboard */; }; 15 | 549B5BCF1DCF41FD009F91E5 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 549B5BC91DCF41FD009F91E5 /* ViewController.swift */; }; 16 | 549B5BD91DCF426F009F91E5 /* HMSegmentedControl.h in Headers */ = {isa = PBXBuildFile; fileRef = 549B5BD71DCF426F009F91E5 /* HMSegmentedControl.h */; settings = {ATTRIBUTES = (Public, ); }; }; 17 | 549B5BDC1DCF426F009F91E5 /* HMSegmentedControl.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 549B5BD51DCF426F009F91E5 /* HMSegmentedControl.framework */; }; 18 | 549B5BDD1DCF426F009F91E5 /* HMSegmentedControl.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 549B5BD51DCF426F009F91E5 /* HMSegmentedControl.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXContainerItemProxy section */ 22 | 549B5BDA1DCF426F009F91E5 /* PBXContainerItemProxy */ = { 23 | isa = PBXContainerItemProxy; 24 | containerPortal = 54974D431D6D06240065A547 /* Project object */; 25 | proxyType = 1; 26 | remoteGlobalIDString = 549B5BD41DCF426F009F91E5; 27 | remoteInfo = HMSegmentedControl; 28 | }; 29 | /* End PBXContainerItemProxy section */ 30 | 31 | /* Begin PBXCopyFilesBuildPhase section */ 32 | 549B5BE11DCF426F009F91E5 /* Embed Frameworks */ = { 33 | isa = PBXCopyFilesBuildPhase; 34 | buildActionMask = 2147483647; 35 | dstPath = ""; 36 | dstSubfolderSpec = 10; 37 | files = ( 38 | 549B5BDD1DCF426F009F91E5 /* HMSegmentedControl.framework in Embed Frameworks */, 39 | ); 40 | name = "Embed Frameworks"; 41 | runOnlyForDeploymentPostprocessing = 0; 42 | }; 43 | /* End PBXCopyFilesBuildPhase section */ 44 | 45 | /* Begin PBXFileReference section */ 46 | 5437C93E1D6D885D00F0A2F7 /* HMSegmentedControl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMSegmentedControl.swift; sourceTree = ""; }; 47 | 54974D4B1D6D06240065A547 /* HMSegmentedControlExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HMSegmentedControlExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 48 | 549B5BC21DCF41FD009F91E5 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 49 | 549B5BC31DCF41FD009F91E5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 50 | 549B5BC51DCF41FD009F91E5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 51 | 549B5BC71DCF41FD009F91E5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 52 | 549B5BC81DCF41FD009F91E5 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 53 | 549B5BC91DCF41FD009F91E5 /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 54 | 549B5BD51DCF426F009F91E5 /* HMSegmentedControl.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = HMSegmentedControl.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 55 | 549B5BD71DCF426F009F91E5 /* HMSegmentedControl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HMSegmentedControl.h; sourceTree = ""; }; 56 | 549B5BD81DCF426F009F91E5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 57 | /* End PBXFileReference section */ 58 | 59 | /* Begin PBXFrameworksBuildPhase section */ 60 | 54974D481D6D06240065A547 /* Frameworks */ = { 61 | isa = PBXFrameworksBuildPhase; 62 | buildActionMask = 2147483647; 63 | files = ( 64 | 549B5BDC1DCF426F009F91E5 /* HMSegmentedControl.framework in Frameworks */, 65 | ); 66 | runOnlyForDeploymentPostprocessing = 0; 67 | }; 68 | 549B5BD11DCF426F009F91E5 /* Frameworks */ = { 69 | isa = PBXFrameworksBuildPhase; 70 | buildActionMask = 2147483647; 71 | files = ( 72 | ); 73 | runOnlyForDeploymentPostprocessing = 0; 74 | }; 75 | /* End PBXFrameworksBuildPhase section */ 76 | 77 | /* Begin PBXGroup section */ 78 | 54974D421D6D06240065A547 = { 79 | isa = PBXGroup; 80 | children = ( 81 | 549B5BC11DCF41FD009F91E5 /* HMSegmentedControlExample */, 82 | 549B5BD61DCF426F009F91E5 /* HMSegmentedControl */, 83 | 54974D4C1D6D06240065A547 /* Products */, 84 | ); 85 | sourceTree = ""; 86 | }; 87 | 54974D4C1D6D06240065A547 /* Products */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | 54974D4B1D6D06240065A547 /* HMSegmentedControlExample.app */, 91 | 549B5BD51DCF426F009F91E5 /* HMSegmentedControl.framework */, 92 | ); 93 | name = Products; 94 | sourceTree = ""; 95 | }; 96 | 549B5BC11DCF41FD009F91E5 /* HMSegmentedControlExample */ = { 97 | isa = PBXGroup; 98 | children = ( 99 | 549B5BC21DCF41FD009F91E5 /* AppDelegate.swift */, 100 | 549B5BC31DCF41FD009F91E5 /* Assets.xcassets */, 101 | 549B5BC41DCF41FD009F91E5 /* LaunchScreen.storyboard */, 102 | 549B5BC61DCF41FD009F91E5 /* Main.storyboard */, 103 | 549B5BC81DCF41FD009F91E5 /* Info.plist */, 104 | 549B5BC91DCF41FD009F91E5 /* ViewController.swift */, 105 | ); 106 | path = HMSegmentedControlExample; 107 | sourceTree = ""; 108 | }; 109 | 549B5BD61DCF426F009F91E5 /* HMSegmentedControl */ = { 110 | isa = PBXGroup; 111 | children = ( 112 | 5437C93E1D6D885D00F0A2F7 /* HMSegmentedControl.swift */, 113 | 549B5BD71DCF426F009F91E5 /* HMSegmentedControl.h */, 114 | 549B5BD81DCF426F009F91E5 /* Info.plist */, 115 | ); 116 | path = HMSegmentedControl; 117 | sourceTree = ""; 118 | }; 119 | /* End PBXGroup section */ 120 | 121 | /* Begin PBXHeadersBuildPhase section */ 122 | 549B5BD21DCF426F009F91E5 /* Headers */ = { 123 | isa = PBXHeadersBuildPhase; 124 | buildActionMask = 2147483647; 125 | files = ( 126 | 549B5BD91DCF426F009F91E5 /* HMSegmentedControl.h in Headers */, 127 | ); 128 | runOnlyForDeploymentPostprocessing = 0; 129 | }; 130 | /* End PBXHeadersBuildPhase section */ 131 | 132 | /* Begin PBXNativeTarget section */ 133 | 54974D4A1D6D06240065A547 /* HMSegmentedControlExample */ = { 134 | isa = PBXNativeTarget; 135 | buildConfigurationList = 54974D5D1D6D06240065A547 /* Build configuration list for PBXNativeTarget "HMSegmentedControlExample" */; 136 | buildPhases = ( 137 | 54974D471D6D06240065A547 /* Sources */, 138 | 54974D481D6D06240065A547 /* Frameworks */, 139 | 54974D491D6D06240065A547 /* Resources */, 140 | 549B5BE11DCF426F009F91E5 /* Embed Frameworks */, 141 | ); 142 | buildRules = ( 143 | ); 144 | dependencies = ( 145 | 549B5BDB1DCF426F009F91E5 /* PBXTargetDependency */, 146 | ); 147 | name = HMSegmentedControlExample; 148 | productName = HMSegmentedControl; 149 | productReference = 54974D4B1D6D06240065A547 /* HMSegmentedControlExample.app */; 150 | productType = "com.apple.product-type.application"; 151 | }; 152 | 549B5BD41DCF426F009F91E5 /* HMSegmentedControl */ = { 153 | isa = PBXNativeTarget; 154 | buildConfigurationList = 549B5BDE1DCF426F009F91E5 /* Build configuration list for PBXNativeTarget "HMSegmentedControl" */; 155 | buildPhases = ( 156 | 549B5BD01DCF426F009F91E5 /* Sources */, 157 | 549B5BD11DCF426F009F91E5 /* Frameworks */, 158 | 549B5BD21DCF426F009F91E5 /* Headers */, 159 | 549B5BD31DCF426F009F91E5 /* Resources */, 160 | ); 161 | buildRules = ( 162 | ); 163 | dependencies = ( 164 | ); 165 | name = HMSegmentedControl; 166 | productName = HMSegmentedControl; 167 | productReference = 549B5BD51DCF426F009F91E5 /* HMSegmentedControl.framework */; 168 | productType = "com.apple.product-type.framework"; 169 | }; 170 | /* End PBXNativeTarget section */ 171 | 172 | /* Begin PBXProject section */ 173 | 54974D431D6D06240065A547 /* Project object */ = { 174 | isa = PBXProject; 175 | attributes = { 176 | LastSwiftUpdateCheck = 0730; 177 | LastUpgradeCheck = 0800; 178 | ORGANIZATIONNAME = Tinybits; 179 | TargetAttributes = { 180 | 54974D4A1D6D06240065A547 = { 181 | CreatedOnToolsVersion = 7.3.1; 182 | LastSwiftMigration = 0820; 183 | }; 184 | 549B5BD41DCF426F009F91E5 = { 185 | CreatedOnToolsVersion = 8.2; 186 | LastSwiftMigration = 0820; 187 | ProvisioningStyle = Automatic; 188 | }; 189 | }; 190 | }; 191 | buildConfigurationList = 54974D461D6D06240065A547 /* Build configuration list for PBXProject "HMSegmentedControl" */; 192 | compatibilityVersion = "Xcode 3.2"; 193 | developmentRegion = English; 194 | hasScannedForEncodings = 0; 195 | knownRegions = ( 196 | en, 197 | Base, 198 | ); 199 | mainGroup = 54974D421D6D06240065A547; 200 | productRefGroup = 54974D4C1D6D06240065A547 /* Products */; 201 | projectDirPath = ""; 202 | projectRoot = ""; 203 | targets = ( 204 | 54974D4A1D6D06240065A547 /* HMSegmentedControlExample */, 205 | 549B5BD41DCF426F009F91E5 /* HMSegmentedControl */, 206 | ); 207 | }; 208 | /* End PBXProject section */ 209 | 210 | /* Begin PBXResourcesBuildPhase section */ 211 | 54974D491D6D06240065A547 /* Resources */ = { 212 | isa = PBXResourcesBuildPhase; 213 | buildActionMask = 2147483647; 214 | files = ( 215 | 549B5BCB1DCF41FD009F91E5 /* Assets.xcassets in Resources */, 216 | 549B5BCD1DCF41FD009F91E5 /* Main.storyboard in Resources */, 217 | 549B5BCC1DCF41FD009F91E5 /* LaunchScreen.storyboard in Resources */, 218 | ); 219 | runOnlyForDeploymentPostprocessing = 0; 220 | }; 221 | 549B5BD31DCF426F009F91E5 /* Resources */ = { 222 | isa = PBXResourcesBuildPhase; 223 | buildActionMask = 2147483647; 224 | files = ( 225 | ); 226 | runOnlyForDeploymentPostprocessing = 0; 227 | }; 228 | /* End PBXResourcesBuildPhase section */ 229 | 230 | /* Begin PBXSourcesBuildPhase section */ 231 | 54974D471D6D06240065A547 /* Sources */ = { 232 | isa = PBXSourcesBuildPhase; 233 | buildActionMask = 2147483647; 234 | files = ( 235 | 549B5BCF1DCF41FD009F91E5 /* ViewController.swift in Sources */, 236 | 549B5BCA1DCF41FD009F91E5 /* AppDelegate.swift in Sources */, 237 | 5437C93F1D6D885D00F0A2F7 /* HMSegmentedControl.swift in Sources */, 238 | ); 239 | runOnlyForDeploymentPostprocessing = 0; 240 | }; 241 | 549B5BD01DCF426F009F91E5 /* Sources */ = { 242 | isa = PBXSourcesBuildPhase; 243 | buildActionMask = 2147483647; 244 | files = ( 245 | ); 246 | runOnlyForDeploymentPostprocessing = 0; 247 | }; 248 | /* End PBXSourcesBuildPhase section */ 249 | 250 | /* Begin PBXTargetDependency section */ 251 | 549B5BDB1DCF426F009F91E5 /* PBXTargetDependency */ = { 252 | isa = PBXTargetDependency; 253 | target = 549B5BD41DCF426F009F91E5 /* HMSegmentedControl */; 254 | targetProxy = 549B5BDA1DCF426F009F91E5 /* PBXContainerItemProxy */; 255 | }; 256 | /* End PBXTargetDependency section */ 257 | 258 | /* Begin PBXVariantGroup section */ 259 | 549B5BC41DCF41FD009F91E5 /* LaunchScreen.storyboard */ = { 260 | isa = PBXVariantGroup; 261 | children = ( 262 | 549B5BC51DCF41FD009F91E5 /* Base */, 263 | ); 264 | name = LaunchScreen.storyboard; 265 | sourceTree = ""; 266 | }; 267 | 549B5BC61DCF41FD009F91E5 /* Main.storyboard */ = { 268 | isa = PBXVariantGroup; 269 | children = ( 270 | 549B5BC71DCF41FD009F91E5 /* Base */, 271 | ); 272 | name = Main.storyboard; 273 | sourceTree = ""; 274 | }; 275 | /* End PBXVariantGroup section */ 276 | 277 | /* Begin XCBuildConfiguration section */ 278 | 54974D5B1D6D06240065A547 /* Debug */ = { 279 | isa = XCBuildConfiguration; 280 | buildSettings = { 281 | ALWAYS_SEARCH_USER_PATHS = NO; 282 | CLANG_ANALYZER_NONNULL = YES; 283 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 284 | CLANG_CXX_LIBRARY = "libc++"; 285 | CLANG_ENABLE_MODULES = YES; 286 | CLANG_ENABLE_OBJC_ARC = YES; 287 | CLANG_WARN_BOOL_CONVERSION = YES; 288 | CLANG_WARN_CONSTANT_CONVERSION = YES; 289 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 290 | CLANG_WARN_EMPTY_BODY = YES; 291 | CLANG_WARN_ENUM_CONVERSION = YES; 292 | CLANG_WARN_INFINITE_RECURSION = YES; 293 | CLANG_WARN_INT_CONVERSION = YES; 294 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 295 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 296 | CLANG_WARN_UNREACHABLE_CODE = YES; 297 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 298 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 299 | COPY_PHASE_STRIP = NO; 300 | DEBUG_INFORMATION_FORMAT = dwarf; 301 | ENABLE_STRICT_OBJC_MSGSEND = YES; 302 | ENABLE_TESTABILITY = YES; 303 | GCC_C_LANGUAGE_STANDARD = gnu99; 304 | GCC_DYNAMIC_NO_PIC = NO; 305 | GCC_NO_COMMON_BLOCKS = YES; 306 | GCC_OPTIMIZATION_LEVEL = 0; 307 | GCC_PREPROCESSOR_DEFINITIONS = ( 308 | "DEBUG=1", 309 | "$(inherited)", 310 | ); 311 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 312 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 313 | GCC_WARN_UNDECLARED_SELECTOR = YES; 314 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 315 | GCC_WARN_UNUSED_FUNCTION = YES; 316 | GCC_WARN_UNUSED_VARIABLE = YES; 317 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 318 | MTL_ENABLE_DEBUG_INFO = YES; 319 | ONLY_ACTIVE_ARCH = YES; 320 | SDKROOT = iphoneos; 321 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 322 | }; 323 | name = Debug; 324 | }; 325 | 54974D5C1D6D06240065A547 /* Release */ = { 326 | isa = XCBuildConfiguration; 327 | buildSettings = { 328 | ALWAYS_SEARCH_USER_PATHS = NO; 329 | CLANG_ANALYZER_NONNULL = YES; 330 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 331 | CLANG_CXX_LIBRARY = "libc++"; 332 | CLANG_ENABLE_MODULES = YES; 333 | CLANG_ENABLE_OBJC_ARC = YES; 334 | CLANG_WARN_BOOL_CONVERSION = YES; 335 | CLANG_WARN_CONSTANT_CONVERSION = YES; 336 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 337 | CLANG_WARN_EMPTY_BODY = YES; 338 | CLANG_WARN_ENUM_CONVERSION = YES; 339 | CLANG_WARN_INFINITE_RECURSION = YES; 340 | CLANG_WARN_INT_CONVERSION = YES; 341 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 342 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 343 | CLANG_WARN_UNREACHABLE_CODE = YES; 344 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 345 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 346 | COPY_PHASE_STRIP = NO; 347 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 348 | ENABLE_NS_ASSERTIONS = NO; 349 | ENABLE_STRICT_OBJC_MSGSEND = YES; 350 | GCC_C_LANGUAGE_STANDARD = gnu99; 351 | GCC_NO_COMMON_BLOCKS = YES; 352 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 353 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 354 | GCC_WARN_UNDECLARED_SELECTOR = YES; 355 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 356 | GCC_WARN_UNUSED_FUNCTION = YES; 357 | GCC_WARN_UNUSED_VARIABLE = YES; 358 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 359 | MTL_ENABLE_DEBUG_INFO = NO; 360 | SDKROOT = iphoneos; 361 | VALIDATE_PRODUCT = YES; 362 | }; 363 | name = Release; 364 | }; 365 | 54974D5E1D6D06240065A547 /* Debug */ = { 366 | isa = XCBuildConfiguration; 367 | buildSettings = { 368 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 369 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 370 | INFOPLIST_FILE = HMSegmentedControlExample/Info.plist; 371 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 372 | PRODUCT_BUNDLE_IDENTIFIER = io.tinybits.HMSegmentedControl; 373 | PRODUCT_NAME = "$(TARGET_NAME)"; 374 | SWIFT_VERSION = 3.0; 375 | }; 376 | name = Debug; 377 | }; 378 | 54974D5F1D6D06240065A547 /* Release */ = { 379 | isa = XCBuildConfiguration; 380 | buildSettings = { 381 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 382 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 383 | INFOPLIST_FILE = HMSegmentedControlExample/Info.plist; 384 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 385 | PRODUCT_BUNDLE_IDENTIFIER = io.tinybits.HMSegmentedControl; 386 | PRODUCT_NAME = "$(TARGET_NAME)"; 387 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 388 | SWIFT_VERSION = 3.0; 389 | }; 390 | name = Release; 391 | }; 392 | 549B5BDF1DCF426F009F91E5 /* Debug */ = { 393 | isa = XCBuildConfiguration; 394 | buildSettings = { 395 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 396 | CODE_SIGN_IDENTITY = ""; 397 | CURRENT_PROJECT_VERSION = 1; 398 | DEFINES_MODULE = YES; 399 | DYLIB_COMPATIBILITY_VERSION = 1; 400 | DYLIB_CURRENT_VERSION = 1; 401 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 402 | INFOPLIST_FILE = HMSegmentedControl/Info.plist; 403 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 404 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 405 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 406 | PRODUCT_BUNDLE_IDENTIFIER = com.heshammegid.HMSegmentedControl; 407 | PRODUCT_NAME = "$(TARGET_NAME)"; 408 | SKIP_INSTALL = YES; 409 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 410 | SWIFT_VERSION = 3.0; 411 | TARGETED_DEVICE_FAMILY = "1,2"; 412 | VERSIONING_SYSTEM = "apple-generic"; 413 | VERSION_INFO_PREFIX = ""; 414 | }; 415 | name = Debug; 416 | }; 417 | 549B5BE01DCF426F009F91E5 /* Release */ = { 418 | isa = XCBuildConfiguration; 419 | buildSettings = { 420 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 421 | CODE_SIGN_IDENTITY = ""; 422 | CURRENT_PROJECT_VERSION = 1; 423 | DEFINES_MODULE = YES; 424 | DYLIB_COMPATIBILITY_VERSION = 1; 425 | DYLIB_CURRENT_VERSION = 1; 426 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 427 | INFOPLIST_FILE = HMSegmentedControl/Info.plist; 428 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 429 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 430 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 431 | PRODUCT_BUNDLE_IDENTIFIER = com.heshammegid.HMSegmentedControl; 432 | PRODUCT_NAME = "$(TARGET_NAME)"; 433 | SKIP_INSTALL = YES; 434 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 435 | SWIFT_VERSION = 3.0; 436 | TARGETED_DEVICE_FAMILY = "1,2"; 437 | VERSIONING_SYSTEM = "apple-generic"; 438 | VERSION_INFO_PREFIX = ""; 439 | }; 440 | name = Release; 441 | }; 442 | /* End XCBuildConfiguration section */ 443 | 444 | /* Begin XCConfigurationList section */ 445 | 54974D461D6D06240065A547 /* Build configuration list for PBXProject "HMSegmentedControl" */ = { 446 | isa = XCConfigurationList; 447 | buildConfigurations = ( 448 | 54974D5B1D6D06240065A547 /* Debug */, 449 | 54974D5C1D6D06240065A547 /* Release */, 450 | ); 451 | defaultConfigurationIsVisible = 0; 452 | defaultConfigurationName = Release; 453 | }; 454 | 54974D5D1D6D06240065A547 /* Build configuration list for PBXNativeTarget "HMSegmentedControlExample" */ = { 455 | isa = XCConfigurationList; 456 | buildConfigurations = ( 457 | 54974D5E1D6D06240065A547 /* Debug */, 458 | 54974D5F1D6D06240065A547 /* Release */, 459 | ); 460 | defaultConfigurationIsVisible = 0; 461 | defaultConfigurationName = Release; 462 | }; 463 | 549B5BDE1DCF426F009F91E5 /* Build configuration list for PBXNativeTarget "HMSegmentedControl" */ = { 464 | isa = XCConfigurationList; 465 | buildConfigurations = ( 466 | 549B5BDF1DCF426F009F91E5 /* Debug */, 467 | 549B5BE01DCF426F009F91E5 /* Release */, 468 | ); 469 | defaultConfigurationIsVisible = 0; 470 | }; 471 | /* End XCConfigurationList section */ 472 | }; 473 | rootObject = 54974D431D6D06240065A547 /* Project object */; 474 | } 475 | -------------------------------------------------------------------------------- /HMSegmentedControl.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /HMSegmentedControl/HMSegmentedControl.h: -------------------------------------------------------------------------------- 1 | // 2 | // HMSegmentedControl.h 3 | // HMSegmentedControl 4 | // 5 | // Created by Hesham Abd-Elmegid on 11/6/16. 6 | // Copyright © 2016 Tinybits. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for HMSegmentedControl. 12 | FOUNDATION_EXPORT double HMSegmentedControlVersionNumber; 13 | 14 | //! Project version string for HMSegmentedControl. 15 | FOUNDATION_EXPORT const unsigned char HMSegmentedControlVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /HMSegmentedControl/HMSegmentedControl.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HMSegmentedControl.swift 3 | // HMSegmentedControl 4 | // 5 | // Created by Hesham Abd-Elmegid on 8/24/16. 6 | // Copyright © 2016 Tinybits. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | // TODO: 12 | // * Add IBInspectable stuff 13 | // * UIAppearance support 14 | // * Set proper access control for propeties and functions 15 | // * Add scroll view 16 | // * Ability to add and remove items after initialization 17 | // * Add delegate callback to configure each button for a state (method should have index, state and button) 18 | // * Move selection indicator to its own private class with all of its properties 19 | 20 | class HMSegmentedControl: UIControl { 21 | enum SelectionIndicatorPosition { 22 | case top 23 | case bottom 24 | } 25 | 26 | enum SelectionIndicatorWidthStyle { 27 | case dynamic // Selection indicator is equal to the segment's label width. 28 | case fixed // Selection indicator is equal to the full width of the segment. 29 | } 30 | 31 | var stackView: UIStackView = { 32 | let stackView = UIStackView() 33 | stackView.axis = .horizontal 34 | stackView.translatesAutoresizingMaskIntoConstraints = false 35 | stackView.distribution = .fillEqually 36 | 37 | return stackView 38 | }() 39 | 40 | lazy var selectionIndicator: UIView = { 41 | let selectionIndicator = UIView() 42 | selectionIndicator.backgroundColor = self.selectionIndicatorColor 43 | selectionIndicator.translatesAutoresizingMaskIntoConstraints = false 44 | return selectionIndicator 45 | }() 46 | 47 | var selectionIndicatorLeadingConstraint: NSLayoutConstraint? 48 | var selectionIndicatorWidthConstraint: NSLayoutConstraint? 49 | var items: [String] 50 | 51 | /// Height of the selection indicator stripe. 52 | var selectionIndicatorHeight: CGFloat = 5.0 53 | 54 | var selectionIndicatorWidthStyle: SelectionIndicatorWidthStyle = .fixed 55 | 56 | /// Position of the selection indicator stripe. 57 | var selectionIndicatorPosition: SelectionIndicatorPosition = .bottom 58 | 59 | /// Color of the selection indicator stripe. 60 | var selectionIndicatorColor: UIColor = .black { 61 | didSet { 62 | self.selectionIndicator.backgroundColor = selectionIndicatorColor 63 | } 64 | } 65 | 66 | /// Text attributes to apply to labels of the unselected segments 67 | var titleTextAttributes: [String:AnyObject]? { 68 | didSet { 69 | if let titleTextAttributes = titleTextAttributes { 70 | set(titleAttributes: titleTextAttributes, forControlState: .normal) 71 | } 72 | } 73 | } 74 | 75 | /// Text attributes to apply to labels of the selected segments 76 | var selectedTitleTextAttributes: [String:AnyObject]? { 77 | didSet { 78 | if let selectedTitleTextAttributes = selectedTitleTextAttributes { 79 | set(titleAttributes: selectedTitleTextAttributes, forControlState: .selected) 80 | } 81 | } 82 | } 83 | 84 | var indexChangedHandler: ((_ index: Int) -> (Void))? 85 | fileprivate(set) var selectedSegmentIndex: Int = 0 { 86 | didSet { 87 | for button in stackView.arrangedSubviews { 88 | if let button = button as? UIButton { 89 | button.isSelected = false 90 | } 91 | } 92 | 93 | let selectedButton = stackView.arrangedSubviews[selectedSegmentIndex] as! UIButton 94 | selectedButton.isSelected = true 95 | } 96 | } 97 | 98 | init(items: [String]) { 99 | self.items = items 100 | 101 | super.init(frame: CGRect.zero) 102 | } 103 | 104 | required init?(coder aDecoder: NSCoder) { 105 | self.items = [] 106 | 107 | super.init(coder: aDecoder) 108 | } 109 | 110 | override func updateConstraints() { 111 | NSLayoutConstraint.activate([ 112 | stackView.widthAnchor.constraint(equalTo: widthAnchor), 113 | stackView.heightAnchor.constraint(equalTo: heightAnchor), 114 | stackView.centerXAnchor.constraint(equalTo: centerXAnchor), 115 | stackView.centerYAnchor.constraint(equalTo: centerYAnchor) 116 | ]) 117 | 118 | 119 | let selectionIndicatorPositionConstraint: NSLayoutConstraint 120 | 121 | if selectionIndicatorPosition == .top { 122 | selectionIndicatorPositionConstraint = selectionIndicator.topAnchor.constraint(equalTo: stackView.topAnchor) 123 | } else { 124 | selectionIndicatorPositionConstraint = selectionIndicator.bottomAnchor.constraint(equalTo: stackView.bottomAnchor) 125 | } 126 | 127 | if selectionIndicatorWidthStyle == .dynamic { 128 | let button = stackView.arrangedSubviews[selectedSegmentIndex] as? UIButton 129 | 130 | if let titleLabel = button?.titleLabel { 131 | selectionIndicatorLeadingConstraint = selectionIndicator.leadingAnchor.constraint(equalTo: titleLabel.leadingAnchor) 132 | selectionIndicatorWidthConstraint = selectionIndicator.widthAnchor.constraint(equalTo: titleLabel.widthAnchor) 133 | } 134 | } else { 135 | selectionIndicatorLeadingConstraint = selectionIndicator.leadingAnchor.constraint(equalTo: stackView.leadingAnchor) 136 | selectionIndicatorWidthConstraint = selectionIndicator.widthAnchor.constraint(equalTo: widthAnchor, multiplier: 1.0 / CGFloat(items.count)) 137 | } 138 | 139 | NSLayoutConstraint.activate([ 140 | selectionIndicatorWidthConstraint!, 141 | selectionIndicator.heightAnchor.constraint(equalToConstant: selectionIndicatorHeight), 142 | selectionIndicatorPositionConstraint, 143 | selectionIndicatorLeadingConstraint! 144 | ]) 145 | 146 | super.updateConstraints() 147 | } 148 | 149 | override func willMove(toSuperview newSuperview: UIView?) { 150 | addSubview(stackView) 151 | addSubview(selectionIndicator) 152 | bringSubview(toFront: selectionIndicator) 153 | 154 | addButtons(forItems: items) 155 | } 156 | 157 | func addButtons(forItems items: [String]) { 158 | for (index, item) in items.enumerated() { 159 | let buttonView = button(forItem: item, atIndex: index) 160 | stackView.addArrangedSubview(buttonView) 161 | } 162 | } 163 | 164 | func button(forItem item: String, atIndex index: Int) -> UIButton { 165 | let button = UIButton() 166 | button.setTitle(item, for: .normal) 167 | button.addTarget(self, action: #selector(HMSegmentedControl.tapped(segmentButton:)), for: .touchUpInside) 168 | // TODO: Set button title text attributes to a dictionary property set by the developer 169 | 170 | if let titleTextAttributes = titleTextAttributes { 171 | let attributedTitle = NSAttributedString(string: item, attributes: titleTextAttributes) 172 | button.setAttributedTitle(attributedTitle, for: .normal) 173 | } else { 174 | button.setTitleColor(.black, for: .normal) 175 | } 176 | 177 | if let selectedTitleTextAttributes = selectedTitleTextAttributes { 178 | let attributedTitle = NSAttributedString(string: item, attributes: selectedTitleTextAttributes) 179 | button.setAttributedTitle(attributedTitle, for: .selected) 180 | } 181 | 182 | button.tag = index 183 | return button 184 | } 185 | 186 | func tapped(segmentButton sender: UIButton) { 187 | let newIndex = sender.tag 188 | let indexChanged: Bool = newIndex != selectedSegmentIndex 189 | selectedSegmentIndex = newIndex 190 | 191 | if let indexChangedHandler = indexChangedHandler, indexChanged == true { 192 | indexChangedHandler(selectedSegmentIndex) 193 | } 194 | 195 | setSelectedSegmentIndex(newIndex, animated: true) 196 | } 197 | 198 | func set(titleAttributes attributes: [String:AnyObject], forControlState state: UIControlState) { 199 | for button in stackView.arrangedSubviews { 200 | if let button = button as? UIButton, let title = button.title(for: state) { 201 | let attributedTitle = NSAttributedString(string: title, attributes: attributes) 202 | button.setAttributedTitle(attributedTitle, for: state) 203 | } 204 | } 205 | } 206 | 207 | /** 208 | Changes the currently selected segment index. 209 | 210 | - parameter index: Index of the segment to select. 211 | - parameter animated: A boolean to specify whether the change should be animated or not 212 | */ 213 | open func setSelectedSegmentIndex(_ index: Int, animated: Bool) { 214 | assert(index < items.count, "Attempting to set index to a segment that does not exist.") 215 | 216 | selectedSegmentIndex = index 217 | 218 | if selectionIndicatorWidthStyle == .dynamic { 219 | let button = stackView.arrangedSubviews[selectedSegmentIndex] as? UIButton 220 | 221 | if let titleLabel = button?.titleLabel { 222 | removeConstraints([selectionIndicatorWidthConstraint!, selectionIndicatorLeadingConstraint!]) 223 | 224 | selectionIndicatorLeadingConstraint = selectionIndicator.leadingAnchor.constraint(equalTo: titleLabel.leadingAnchor) 225 | selectionIndicatorWidthConstraint = selectionIndicator.widthAnchor.constraint(equalTo: titleLabel.widthAnchor) 226 | 227 | NSLayoutConstraint.activate([selectionIndicatorWidthConstraint!, selectionIndicatorLeadingConstraint!]) 228 | } 229 | } else { 230 | let segmentWidth = stackView.frame.size.width / CGFloat(items.count) 231 | selectionIndicatorLeadingConstraint?.constant = segmentWidth * CGFloat(index) 232 | } 233 | 234 | if animated { 235 | UIView.animate(withDuration: 0.25, animations: { 236 | self.layoutIfNeeded() 237 | }) 238 | } else { 239 | self.layoutIfNeeded() 240 | } 241 | } 242 | } 243 | -------------------------------------------------------------------------------- /HMSegmentedControl/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 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSPrincipalClass 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /HMSegmentedControlExample/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // HMSegmentedControl 4 | // 5 | // Created by Hesham Abd-Elmegid on 8/24/16. 6 | // Copyright © 2016 Tinybits. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool { 17 | return true 18 | } 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /HMSegmentedControlExample/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 | } -------------------------------------------------------------------------------- /HMSegmentedControlExample/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 | -------------------------------------------------------------------------------- /HMSegmentedControlExample/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /HMSegmentedControlExample/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 | -------------------------------------------------------------------------------- /HMSegmentedControlExample/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // HMSegmentedControl 4 | // 5 | // Created by Hesham Abd-Elmegid on 8/24/16. 6 | // Copyright © 2016 Tinybits. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import HMSegmentedControl 11 | 12 | class ViewController: UIViewController { 13 | let segmentedControl = HMSegmentedControl(items: ["One", "Two", "Three"]) 14 | 15 | override func viewDidLoad() { 16 | view.addSubview(segmentedControl) 17 | 18 | segmentedControl.backgroundColor = #colorLiteral(red: 0.7683569193, green: 0.9300123453, blue: 0.9995251894, alpha: 1) 19 | segmentedControl.translatesAutoresizingMaskIntoConstraints = false 20 | segmentedControl.selectionIndicatorPosition = .bottom 21 | segmentedControl.selectionIndicatorColor = #colorLiteral(red: 0.1142767668, green: 0.3181744218, blue: 0.4912756383, alpha: 1) 22 | 23 | segmentedControl.titleTextAttributes = [ 24 | NSForegroundColorAttributeName : #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1), 25 | NSFontAttributeName : UIFont.systemFont(ofSize: 17) 26 | ] 27 | 28 | segmentedControl.selectedTitleTextAttributes = [ 29 | NSForegroundColorAttributeName : #colorLiteral(red: 0.05439098924, green: 0.1344551742, blue: 0.1884709597, alpha: 1), 30 | NSFontAttributeName : UIFont.boldSystemFont(ofSize: 17) 31 | ] 32 | 33 | segmentedControl.indexChangedHandler = { index in 34 | print(index) 35 | // print(self.segmentedControl.selectedSegmentIndex) 36 | // self.segmentedControl.selectedSegmentIndex = 1 37 | } 38 | 39 | NSLayoutConstraint.activate( 40 | [segmentedControl.leftAnchor.constraint(equalTo: view.leftAnchor), 41 | segmentedControl.heightAnchor.constraint(equalToConstant: 50), 42 | segmentedControl.rightAnchor.constraint(equalTo: view.rightAnchor), 43 | segmentedControl.topAnchor.constraint(equalTo: view.topAnchor, constant: 40)] 44 | ) 45 | } 46 | 47 | override func viewDidAppear(_ animated: Bool) { 48 | segmentedControl.setSelectedSegmentIndex(2, animated: false) 49 | } 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HMSegmentedControl-Swift 2 | 3 | This repo is an attempt to create a version of the original [**HMSegmentedControl**](https://github.com/HeshamMegid/HMSegmentedControl) that uses modern Cocoa APIs and Swift 3.0. 4 | 5 | HMSegmentedControl-Swift currently only has a small subset of the features of **HMSegmentedControl**, and it's not ready for production use yet. Feel free to create issues and submit pull requests to help port over all the features. 6 | --------------------------------------------------------------------------------