├── .DS_Store ├── .gitignore ├── LICENSE.md ├── README.md └── SegmentControl ├── .DS_Store ├── Screen Recording 2022-10-05 at 12.32.05 AM.mov ├── SegmentControl.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist └── SegmentControl ├── Assets.xcassets ├── AccentColor.colorset │ └── Contents.json ├── AppIcon.appiconset │ └── Contents.json ├── Contents.json ├── Day.imageset │ ├── Contents.json │ └── Day.jpg ├── Evening.imageset │ ├── Contents.json │ └── Evening.jpg └── Morning.imageset │ ├── Contents.json │ └── Morning.jpg ├── ContentView.swift ├── Preview Content └── Preview Assets.xcassets │ └── Contents.json ├── SegmentControlApp.swift └── SegmentControlView.swift /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pratikg29/Custom-SegmentView/3f4acba3adcd8934c7e3fab9019b493b9cc12778/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## User settings 6 | xcuserdata/ 7 | 8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 9 | *.xcscmblueprint 10 | *.xccheckout 11 | 12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 13 | build/ 14 | DerivedData/ 15 | *.moved-aside 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | 28 | ## App packaging 29 | *.ipa 30 | *.dSYM.zip 31 | *.dSYM 32 | 33 | ## Playgrounds 34 | timeline.xctimeline 35 | playground.xcworkspace 36 | 37 | # Swift Package Manager 38 | # 39 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 40 | # Packages/ 41 | # Package.pins 42 | # Package.resolved 43 | # *.xcodeproj 44 | # 45 | # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata 46 | # hence it is not needed unless you have added a package configuration file to your project 47 | # .swiftpm 48 | 49 | .build/ 50 | 51 | # CocoaPods 52 | # 53 | # We recommend against adding the Pods directory to your .gitignore. However 54 | # you should judge for yourself, the pros and cons are mentioned at: 55 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 56 | # 57 | # Pods/ 58 | # 59 | # Add this line if you want to avoid checking in source code from the Xcode workspace 60 | # *.xcworkspace 61 | 62 | # Carthage 63 | # 64 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 65 | # Carthage/Checkouts 66 | 67 | Carthage/Build/ 68 | 69 | # Accio dependency management 70 | Dependencies/ 71 | .accio/ 72 | 73 | # fastlane 74 | # 75 | # It is recommended to not store the screenshots in the git repo. 76 | # Instead, use fastlane to re-generate the screenshots whenever they are needed. 77 | # For more information about the recommended setup visit: 78 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 79 | 80 | fastlane/report.xml 81 | fastlane/Preview.html 82 | fastlane/screenshots/**/*.png 83 | fastlane/test_output 84 | 85 | # Code Injection 86 | # 87 | # After new code Injection tools there's a generated folder /iOSInjectionProject 88 | # https://github.com/johnno1962/injectionforxcode 89 | 90 | iOSInjectionProject/ 91 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Pratik Gadhesariya 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Custom-SegmentView 2 | created customised segment control in SwiftUI. 3 | 4 | This is an customised SegmentView created in SwiftUI. 5 | SwiftUI is very powerful and fully customisable framework to design iOS apps. Here is one cool example of that. 6 | 7 | Support me: 8 | https://www.paypal.com/paypalme/PratikGadhesariya 9 | 10 | ![Image 2](https://user-images.githubusercontent.com/35287467/195035153-357aa7f7-0c66-45c9-aa66-fcdb5d5bbd6c.png) 11 | 12 | 13 | https://user-images.githubusercontent.com/35287467/195035215-73c96bae-18f0-46ee-a10b-c7d6480a295a.mp4 14 | 15 | -------------------------------------------------------------------------------- /SegmentControl/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pratikg29/Custom-SegmentView/3f4acba3adcd8934c7e3fab9019b493b9cc12778/SegmentControl/.DS_Store -------------------------------------------------------------------------------- /SegmentControl/Screen Recording 2022-10-05 at 12.32.05 AM.mov: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pratikg29/Custom-SegmentView/3f4acba3adcd8934c7e3fab9019b493b9cc12778/SegmentControl/Screen Recording 2022-10-05 at 12.32.05 AM.mov -------------------------------------------------------------------------------- /SegmentControl/SegmentControl.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 55; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 3053CED128EACFA9002F551E /* SegmentControlApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3053CED028EACFA9002F551E /* SegmentControlApp.swift */; }; 11 | 3053CED328EACFA9002F551E /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3053CED228EACFA9002F551E /* ContentView.swift */; }; 12 | 3053CED528EACFAE002F551E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3053CED428EACFAE002F551E /* Assets.xcassets */; }; 13 | 3053CED828EACFAE002F551E /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3053CED728EACFAE002F551E /* Preview Assets.xcassets */; }; 14 | 3053CEDF28EACFE2002F551E /* SegmentControlView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3053CEDE28EACFE2002F551E /* SegmentControlView.swift */; }; 15 | /* End PBXBuildFile section */ 16 | 17 | /* Begin PBXFileReference section */ 18 | 3053CECD28EACFA9002F551E /* SegmentControl.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SegmentControl.app; sourceTree = BUILT_PRODUCTS_DIR; }; 19 | 3053CED028EACFA9002F551E /* SegmentControlApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentControlApp.swift; sourceTree = ""; }; 20 | 3053CED228EACFA9002F551E /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 21 | 3053CED428EACFAE002F551E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 22 | 3053CED728EACFAE002F551E /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 23 | 3053CEDE28EACFE2002F551E /* SegmentControlView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentControlView.swift; sourceTree = ""; }; 24 | /* End PBXFileReference section */ 25 | 26 | /* Begin PBXFrameworksBuildPhase section */ 27 | 3053CECA28EACFA9002F551E /* Frameworks */ = { 28 | isa = PBXFrameworksBuildPhase; 29 | buildActionMask = 2147483647; 30 | files = ( 31 | ); 32 | runOnlyForDeploymentPostprocessing = 0; 33 | }; 34 | /* End PBXFrameworksBuildPhase section */ 35 | 36 | /* Begin PBXGroup section */ 37 | 3053CEC428EACFA9002F551E = { 38 | isa = PBXGroup; 39 | children = ( 40 | 3053CECF28EACFA9002F551E /* SegmentControl */, 41 | 3053CECE28EACFA9002F551E /* Products */, 42 | ); 43 | sourceTree = ""; 44 | }; 45 | 3053CECE28EACFA9002F551E /* Products */ = { 46 | isa = PBXGroup; 47 | children = ( 48 | 3053CECD28EACFA9002F551E /* SegmentControl.app */, 49 | ); 50 | name = Products; 51 | sourceTree = ""; 52 | }; 53 | 3053CECF28EACFA9002F551E /* SegmentControl */ = { 54 | isa = PBXGroup; 55 | children = ( 56 | 3053CED028EACFA9002F551E /* SegmentControlApp.swift */, 57 | 3053CED228EACFA9002F551E /* ContentView.swift */, 58 | 3053CEDE28EACFE2002F551E /* SegmentControlView.swift */, 59 | 3053CED428EACFAE002F551E /* Assets.xcassets */, 60 | 3053CED628EACFAE002F551E /* Preview Content */, 61 | ); 62 | path = SegmentControl; 63 | sourceTree = ""; 64 | }; 65 | 3053CED628EACFAE002F551E /* Preview Content */ = { 66 | isa = PBXGroup; 67 | children = ( 68 | 3053CED728EACFAE002F551E /* Preview Assets.xcassets */, 69 | ); 70 | path = "Preview Content"; 71 | sourceTree = ""; 72 | }; 73 | /* End PBXGroup section */ 74 | 75 | /* Begin PBXNativeTarget section */ 76 | 3053CECC28EACFA9002F551E /* SegmentControl */ = { 77 | isa = PBXNativeTarget; 78 | buildConfigurationList = 3053CEDB28EACFAE002F551E /* Build configuration list for PBXNativeTarget "SegmentControl" */; 79 | buildPhases = ( 80 | 3053CEC928EACFA9002F551E /* Sources */, 81 | 3053CECA28EACFA9002F551E /* Frameworks */, 82 | 3053CECB28EACFA9002F551E /* Resources */, 83 | ); 84 | buildRules = ( 85 | ); 86 | dependencies = ( 87 | ); 88 | name = SegmentControl; 89 | productName = SegmentControl; 90 | productReference = 3053CECD28EACFA9002F551E /* SegmentControl.app */; 91 | productType = "com.apple.product-type.application"; 92 | }; 93 | /* End PBXNativeTarget section */ 94 | 95 | /* Begin PBXProject section */ 96 | 3053CEC528EACFA9002F551E /* Project object */ = { 97 | isa = PBXProject; 98 | attributes = { 99 | BuildIndependentTargetsInParallel = 1; 100 | LastSwiftUpdateCheck = 1340; 101 | LastUpgradeCheck = 1340; 102 | TargetAttributes = { 103 | 3053CECC28EACFA9002F551E = { 104 | CreatedOnToolsVersion = 13.4.1; 105 | }; 106 | }; 107 | }; 108 | buildConfigurationList = 3053CEC828EACFA9002F551E /* Build configuration list for PBXProject "SegmentControl" */; 109 | compatibilityVersion = "Xcode 13.0"; 110 | developmentRegion = en; 111 | hasScannedForEncodings = 0; 112 | knownRegions = ( 113 | en, 114 | Base, 115 | ); 116 | mainGroup = 3053CEC428EACFA9002F551E; 117 | productRefGroup = 3053CECE28EACFA9002F551E /* Products */; 118 | projectDirPath = ""; 119 | projectRoot = ""; 120 | targets = ( 121 | 3053CECC28EACFA9002F551E /* SegmentControl */, 122 | ); 123 | }; 124 | /* End PBXProject section */ 125 | 126 | /* Begin PBXResourcesBuildPhase section */ 127 | 3053CECB28EACFA9002F551E /* Resources */ = { 128 | isa = PBXResourcesBuildPhase; 129 | buildActionMask = 2147483647; 130 | files = ( 131 | 3053CED828EACFAE002F551E /* Preview Assets.xcassets in Resources */, 132 | 3053CED528EACFAE002F551E /* Assets.xcassets in Resources */, 133 | ); 134 | runOnlyForDeploymentPostprocessing = 0; 135 | }; 136 | /* End PBXResourcesBuildPhase section */ 137 | 138 | /* Begin PBXSourcesBuildPhase section */ 139 | 3053CEC928EACFA9002F551E /* Sources */ = { 140 | isa = PBXSourcesBuildPhase; 141 | buildActionMask = 2147483647; 142 | files = ( 143 | 3053CED328EACFA9002F551E /* ContentView.swift in Sources */, 144 | 3053CED128EACFA9002F551E /* SegmentControlApp.swift in Sources */, 145 | 3053CEDF28EACFE2002F551E /* SegmentControlView.swift in Sources */, 146 | ); 147 | runOnlyForDeploymentPostprocessing = 0; 148 | }; 149 | /* End PBXSourcesBuildPhase section */ 150 | 151 | /* Begin XCBuildConfiguration section */ 152 | 3053CED928EACFAE002F551E /* Debug */ = { 153 | isa = XCBuildConfiguration; 154 | buildSettings = { 155 | ALWAYS_SEARCH_USER_PATHS = NO; 156 | CLANG_ANALYZER_NONNULL = YES; 157 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 158 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 159 | CLANG_ENABLE_MODULES = YES; 160 | CLANG_ENABLE_OBJC_ARC = YES; 161 | CLANG_ENABLE_OBJC_WEAK = YES; 162 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 163 | CLANG_WARN_BOOL_CONVERSION = YES; 164 | CLANG_WARN_COMMA = YES; 165 | CLANG_WARN_CONSTANT_CONVERSION = YES; 166 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 167 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 168 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 169 | CLANG_WARN_EMPTY_BODY = YES; 170 | CLANG_WARN_ENUM_CONVERSION = YES; 171 | CLANG_WARN_INFINITE_RECURSION = YES; 172 | CLANG_WARN_INT_CONVERSION = YES; 173 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 174 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 175 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 176 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 177 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 178 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 179 | CLANG_WARN_STRICT_PROTOTYPES = YES; 180 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 181 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 182 | CLANG_WARN_UNREACHABLE_CODE = YES; 183 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 184 | COPY_PHASE_STRIP = NO; 185 | DEBUG_INFORMATION_FORMAT = dwarf; 186 | ENABLE_STRICT_OBJC_MSGSEND = YES; 187 | ENABLE_TESTABILITY = YES; 188 | GCC_C_LANGUAGE_STANDARD = gnu11; 189 | GCC_DYNAMIC_NO_PIC = NO; 190 | GCC_NO_COMMON_BLOCKS = YES; 191 | GCC_OPTIMIZATION_LEVEL = 0; 192 | GCC_PREPROCESSOR_DEFINITIONS = ( 193 | "DEBUG=1", 194 | "$(inherited)", 195 | ); 196 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 197 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 198 | GCC_WARN_UNDECLARED_SELECTOR = YES; 199 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 200 | GCC_WARN_UNUSED_FUNCTION = YES; 201 | GCC_WARN_UNUSED_VARIABLE = YES; 202 | IPHONEOS_DEPLOYMENT_TARGET = 15.5; 203 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 204 | MTL_FAST_MATH = YES; 205 | ONLY_ACTIVE_ARCH = YES; 206 | SDKROOT = iphoneos; 207 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 208 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 209 | }; 210 | name = Debug; 211 | }; 212 | 3053CEDA28EACFAE002F551E /* Release */ = { 213 | isa = XCBuildConfiguration; 214 | buildSettings = { 215 | ALWAYS_SEARCH_USER_PATHS = NO; 216 | CLANG_ANALYZER_NONNULL = YES; 217 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 218 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 219 | CLANG_ENABLE_MODULES = YES; 220 | CLANG_ENABLE_OBJC_ARC = YES; 221 | CLANG_ENABLE_OBJC_WEAK = YES; 222 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 223 | CLANG_WARN_BOOL_CONVERSION = YES; 224 | CLANG_WARN_COMMA = YES; 225 | CLANG_WARN_CONSTANT_CONVERSION = YES; 226 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 227 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 228 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 229 | CLANG_WARN_EMPTY_BODY = YES; 230 | CLANG_WARN_ENUM_CONVERSION = YES; 231 | CLANG_WARN_INFINITE_RECURSION = YES; 232 | CLANG_WARN_INT_CONVERSION = YES; 233 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 234 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 235 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 236 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 237 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 238 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 239 | CLANG_WARN_STRICT_PROTOTYPES = YES; 240 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 241 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 242 | CLANG_WARN_UNREACHABLE_CODE = YES; 243 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 244 | COPY_PHASE_STRIP = NO; 245 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 246 | ENABLE_NS_ASSERTIONS = NO; 247 | ENABLE_STRICT_OBJC_MSGSEND = YES; 248 | GCC_C_LANGUAGE_STANDARD = gnu11; 249 | GCC_NO_COMMON_BLOCKS = YES; 250 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 251 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 252 | GCC_WARN_UNDECLARED_SELECTOR = YES; 253 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 254 | GCC_WARN_UNUSED_FUNCTION = YES; 255 | GCC_WARN_UNUSED_VARIABLE = YES; 256 | IPHONEOS_DEPLOYMENT_TARGET = 15.5; 257 | MTL_ENABLE_DEBUG_INFO = NO; 258 | MTL_FAST_MATH = YES; 259 | SDKROOT = iphoneos; 260 | SWIFT_COMPILATION_MODE = wholemodule; 261 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 262 | VALIDATE_PRODUCT = YES; 263 | }; 264 | name = Release; 265 | }; 266 | 3053CEDC28EACFAE002F551E /* Debug */ = { 267 | isa = XCBuildConfiguration; 268 | buildSettings = { 269 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 270 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 271 | CODE_SIGN_STYLE = Automatic; 272 | CURRENT_PROJECT_VERSION = 1; 273 | DEVELOPMENT_ASSET_PATHS = "\"SegmentControl/Preview Content\""; 274 | ENABLE_PREVIEWS = YES; 275 | GENERATE_INFOPLIST_FILE = YES; 276 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 277 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 278 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 279 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 280 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 281 | LD_RUNPATH_SEARCH_PATHS = ( 282 | "$(inherited)", 283 | "@executable_path/Frameworks", 284 | ); 285 | MARKETING_VERSION = 1.0; 286 | PRODUCT_BUNDLE_IDENTIFIER = com.pratik.SegmentControl; 287 | PRODUCT_NAME = "$(TARGET_NAME)"; 288 | SWIFT_EMIT_LOC_STRINGS = YES; 289 | SWIFT_VERSION = 5.0; 290 | TARGETED_DEVICE_FAMILY = "1,2"; 291 | }; 292 | name = Debug; 293 | }; 294 | 3053CEDD28EACFAE002F551E /* Release */ = { 295 | isa = XCBuildConfiguration; 296 | buildSettings = { 297 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 298 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 299 | CODE_SIGN_STYLE = Automatic; 300 | CURRENT_PROJECT_VERSION = 1; 301 | DEVELOPMENT_ASSET_PATHS = "\"SegmentControl/Preview Content\""; 302 | ENABLE_PREVIEWS = YES; 303 | GENERATE_INFOPLIST_FILE = YES; 304 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 305 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 306 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 307 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 308 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 309 | LD_RUNPATH_SEARCH_PATHS = ( 310 | "$(inherited)", 311 | "@executable_path/Frameworks", 312 | ); 313 | MARKETING_VERSION = 1.0; 314 | PRODUCT_BUNDLE_IDENTIFIER = com.pratik.SegmentControl; 315 | PRODUCT_NAME = "$(TARGET_NAME)"; 316 | SWIFT_EMIT_LOC_STRINGS = YES; 317 | SWIFT_VERSION = 5.0; 318 | TARGETED_DEVICE_FAMILY = "1,2"; 319 | }; 320 | name = Release; 321 | }; 322 | /* End XCBuildConfiguration section */ 323 | 324 | /* Begin XCConfigurationList section */ 325 | 3053CEC828EACFA9002F551E /* Build configuration list for PBXProject "SegmentControl" */ = { 326 | isa = XCConfigurationList; 327 | buildConfigurations = ( 328 | 3053CED928EACFAE002F551E /* Debug */, 329 | 3053CEDA28EACFAE002F551E /* Release */, 330 | ); 331 | defaultConfigurationIsVisible = 0; 332 | defaultConfigurationName = Release; 333 | }; 334 | 3053CEDB28EACFAE002F551E /* Build configuration list for PBXNativeTarget "SegmentControl" */ = { 335 | isa = XCConfigurationList; 336 | buildConfigurations = ( 337 | 3053CEDC28EACFAE002F551E /* Debug */, 338 | 3053CEDD28EACFAE002F551E /* Release */, 339 | ); 340 | defaultConfigurationIsVisible = 0; 341 | defaultConfigurationName = Release; 342 | }; 343 | /* End XCConfigurationList section */ 344 | }; 345 | rootObject = 3053CEC528EACFA9002F551E /* Project object */; 346 | } 347 | -------------------------------------------------------------------------------- /SegmentControl/SegmentControl.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SegmentControl/SegmentControl.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /SegmentControl/SegmentControl/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /SegmentControl/SegmentControl/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /SegmentControl/SegmentControl/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /SegmentControl/SegmentControl/Assets.xcassets/Day.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Day.jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /SegmentControl/SegmentControl/Assets.xcassets/Day.imageset/Day.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pratikg29/Custom-SegmentView/3f4acba3adcd8934c7e3fab9019b493b9cc12778/SegmentControl/SegmentControl/Assets.xcassets/Day.imageset/Day.jpg -------------------------------------------------------------------------------- /SegmentControl/SegmentControl/Assets.xcassets/Evening.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Evening.jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /SegmentControl/SegmentControl/Assets.xcassets/Evening.imageset/Evening.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pratikg29/Custom-SegmentView/3f4acba3adcd8934c7e3fab9019b493b9cc12778/SegmentControl/SegmentControl/Assets.xcassets/Evening.imageset/Evening.jpg -------------------------------------------------------------------------------- /SegmentControl/SegmentControl/Assets.xcassets/Morning.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Morning.jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /SegmentControl/SegmentControl/Assets.xcassets/Morning.imageset/Morning.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pratikg29/Custom-SegmentView/3f4acba3adcd8934c7e3fab9019b493b9cc12778/SegmentControl/SegmentControl/Assets.xcassets/Morning.imageset/Morning.jpg -------------------------------------------------------------------------------- /SegmentControl/SegmentControl/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // SegmentControl 4 | // 5 | // Created by Pratik on 03/10/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct ContentView: View { 11 | @State private var selectedSegment1: Segment = .morning 12 | @State private var selectedSegment2: Segment = .morning 13 | @State var animation: Animation = .default 14 | @State var themeColor: Color = .primary 15 | @State var cornerRadius: CGFloat = 10 16 | @State var selectedAnimationIndex: Int = 0 17 | 18 | 19 | var body: some View { 20 | GeometryReader { bounds in 21 | VStack(spacing: 100) { 22 | VStack(spacing: 20) { 23 | SegmentControlView(segments: Segment.allCases, 24 | selected: $selectedSegment1, 25 | titleNormalColor: themeColor, 26 | titleSelectedColor: .white, 27 | bgColor: themeColor, 28 | animation: animation) { segment in 29 | Text(segment.title) 30 | .font(.system(size: 20, weight: .semibold, design: .rounded)) 31 | .padding(.horizontal) 32 | .padding(.vertical, 8) 33 | } background: { 34 | RoundedRectangle(cornerRadius: cornerRadius, style: .continuous) 35 | } 36 | .frame(height: 37) 37 | 38 | SegmentControlView(segments: Segment.allCases, 39 | selected: $selectedSegment2, 40 | titleNormalColor: themeColor, 41 | titleSelectedColor: .white, 42 | bgColor: themeColor, 43 | animation: animation) { segment in 44 | Image(systemName: segment.icon) 45 | .font(.system(size: 20, weight: .bold, design: .rounded)) 46 | .padding(.horizontal) 47 | .padding(.vertical, 8) 48 | } background: { 49 | RoundedRectangle(cornerRadius: cornerRadius, style: .continuous) 50 | } 51 | .frame(height: 37) 52 | } 53 | .padding() 54 | .background(Color.white.cornerRadius(20)) 55 | 56 | VStack(spacing: 20) { 57 | Slider(value: $cornerRadius, in: 0...20) { 58 | Text("Corner Radius") 59 | } onEditingChanged: { changed in 60 | 61 | } 62 | 63 | Picker("Animation", selection: $selectedAnimationIndex) { 64 | Text("Default").tag(0) 65 | Text("Spring").tag(1) 66 | } 67 | .pickerStyle(.segmented) 68 | .onChange(of: selectedAnimationIndex) { newValue in 69 | switch newValue { 70 | case 0: 71 | animation = .default 72 | case 1: 73 | animation = .spring(response: 0.6, dampingFraction: 0.6, blendDuration: 0.6) 74 | default: 75 | animation = .default 76 | } 77 | } 78 | 79 | ColorPicker(selection: $themeColor) { 80 | Text("Theme") 81 | .bold() 82 | } 83 | } 84 | .padding(.horizontal) 85 | } 86 | .padding(.top, 50) 87 | .padding(.horizontal) 88 | } 89 | .background(Color.init(white: 0.95)) 90 | } 91 | } 92 | 93 | struct ContentView_Previews: PreviewProvider { 94 | static var previews: some View { 95 | ContentView() 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /SegmentControl/SegmentControl/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /SegmentControl/SegmentControl/SegmentControlApp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SegmentControlApp.swift 3 | // SegmentControl 4 | // 5 | // Created by Pratik on 03/10/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | @main 11 | struct SegmentControlApp: App { 12 | var body: some Scene { 13 | WindowGroup { 14 | ContentView() 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /SegmentControl/SegmentControl/SegmentControlView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SegmentControlView.swift 3 | // SegmentControl 4 | // 5 | // Created by Pratik on 03/10/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct SegmentControlView: View { 11 | let segments: [ID] 12 | @Binding var selected: ID 13 | var titleNormalColor: Color 14 | var titleSelectedColor: Color 15 | var bgColor: Color 16 | let animation: Animation 17 | @ViewBuilder var content: (ID) -> Content 18 | @ViewBuilder var background: () -> Background 19 | 20 | @Namespace private var namespace 21 | 22 | var body: some View { 23 | GeometryReader { bounds in 24 | HStack(spacing: 0) { 25 | ForEach(segments) { segment in 26 | NewSegmentButtonView(id: segment, 27 | selectedId: $selected, 28 | titleNormalColor: titleNormalColor, 29 | titleSelectedColor: titleSelectedColor, 30 | bgColor: bgColor, 31 | animation: animation, 32 | namespace: namespace) { 33 | content(segment) 34 | } background: { 35 | background() 36 | } 37 | .frame(width: bounds.size.width / CGFloat(segments.count)) 38 | } 39 | } 40 | .background { 41 | background() 42 | .fill(bgColor.opacity(0.1)) 43 | .overlay( 44 | background() 45 | .stroke(style: StrokeStyle(lineWidth: 1.5)) 46 | .foregroundColor(bgColor.opacity(0.2)) 47 | ) 48 | } 49 | } 50 | } 51 | } 52 | 53 | fileprivate struct NewSegmentButtonView : View { 54 | let id: ID 55 | @Binding var selectedId: ID 56 | var titleNormalColor: Color 57 | var titleSelectedColor: Color 58 | var bgColor: Color 59 | var animation: Animation 60 | var namespace: Namespace.ID 61 | @ViewBuilder var content: () -> Content 62 | @ViewBuilder var background: () -> Background 63 | 64 | 65 | var body: some View { 66 | GeometryReader { bounds in 67 | Button { 68 | withAnimation(animation) { 69 | selectedId = id 70 | } 71 | } label: { 72 | content() 73 | } 74 | .frame(width: bounds.size.width, height: bounds.size.height) 75 | .scaleEffect(selectedId.id == id.id ? 1 : 0.8) 76 | .clipShape(background()) 77 | .foregroundColor(selectedId.id == id.id ? titleSelectedColor : titleNormalColor) 78 | .background(buttonBackground) 79 | } 80 | } 81 | 82 | @ViewBuilder private var buttonBackground: some View { 83 | if selectedId.id == id.id { 84 | background() 85 | .fill(bgColor) 86 | .matchedGeometryEffect(id: "SelectedTab", in: namespace) 87 | } 88 | } 89 | } 90 | 91 | enum Segment: Identifiable, CaseIterable { 92 | case morning, noon, evening 93 | 94 | var id: String { 95 | title 96 | } 97 | 98 | var title: String { 99 | switch self { 100 | case .morning: 101 | return "Morning" 102 | case .noon: 103 | return "Noon" 104 | case .evening: 105 | return "Evening" 106 | } 107 | } 108 | 109 | var icon: String { 110 | switch self { 111 | case .morning: 112 | return "sun.and.horizon.fill" 113 | case .noon: 114 | return "sun.max.fill" 115 | case .evening: 116 | return "moon.fill" 117 | } 118 | } 119 | 120 | var image: String { 121 | switch self { 122 | case .morning: 123 | return "Morning" 124 | case .noon: 125 | return "Day" 126 | case .evening: 127 | return "Evening" 128 | } 129 | } 130 | } 131 | --------------------------------------------------------------------------------