├── LICENSE ├── README.md ├── TCSegmentedView.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── os.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── os.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── TCSegmentedView.xcscheme │ └── xcschememanagement.plist └── TCSegmentedView ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Info.plist ├── Main.storyboard ├── TCSegmentedView ├── TCSegmentedView.h └── TCSegmentedView.m ├── ViewController.h ├── ViewController.m ├── demo └── demo.gif └── main.m /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 | # TCSegmentedView 2 | Easy to create & custom segmented view 3 | 4 | ![Example](https://github.com/tranchuong/TCSegmentedView/blob/master/TCSegmentedView/demo/demo.gif) 5 | 6 | ## Usage Examples 7 | An Objective-C example project demonstrating customization options is included in the TCSegmentedView directory. 8 | 9 | ### Objective-C 10 | 11 | ```objc 12 | // Import the class and create an TCSegmentedView instance 13 | #import "TCSegmentedView.h" 14 | 15 | // Add segmentedView to view 16 | 17 | [self.view addSubview:self.segmentedView1]; 18 | [self.view addSubview:self.segmentedView2]; 19 | [self.view addSubview:self.segmentedView3]; 20 | 21 | // Init segmentedView 22 | -(TCSegmentedView *)segmentedView1 23 | { 24 | if (!_segmentedView1) { 25 | _segmentedView1 = [TCSegmentedView segmentedWithActiveItems:@[@"01. Segment 1",@"02. Segment 2", @"03. Segment 3", @"04. Segment 4"] normalItems:@[@"01",@"02",@"03", @"04"] frame:CGRectMake(16, 60, self.view.frame.size.width - 32, 30)]; 26 | [_segmentedView1 setBackgroundColor:[UIColor clearColor]]; 27 | [_segmentedView1 setNormalColor:[UIColor whiteColor] font:AS_FONT_SF_TEXT_MEDIUM(14)]; 28 | [_segmentedView1 setSelectedColor:[UIColor whiteColor] font:AS_FONT_SF_TEXT_MEDIUM(14)]; 29 | 30 | _segmentedView1.delegate = self; 31 | } 32 | return _segmentedView1; 33 | } 34 | 35 | -(TCSegmentedView *)segmentedView2 36 | { 37 | if (!_segmentedView2) { 38 | _segmentedView2 = [TCSegmentedView segmentedWithActiveItems:@[@"01. Address",@"02. Basic Info", @"03. Photos"] normalItems:@[@"1",@"2",@"3"] frame:CGRectMake((self.view.frame.size.width - 240)/2, 160, 240, 30)]; 39 | [_segmentedView2 setBackgroundColor:[UIColor clearColor]]; 40 | [_segmentedView2 setNormalColor:[UIColor whiteColor] font:AS_FONT_SF_TEXT_REGULAR(12)]; 41 | [_segmentedView2 setSelectedColor:[UIColor whiteColor] font:AS_FONT_SF_TEXT_BOLD(14)]; 42 | _segmentedView2.backgroundNormalColor = [UIColor brownColor]; 43 | _segmentedView2.backgroundActiveColor = [UIColor redColor]; 44 | _segmentedView2.dashLineColor = [UIColor blueColor]; 45 | 46 | _segmentedView2.delegate = self; 47 | } 48 | return _segmentedView2; 49 | } 50 | 51 | -(TCSegmentedView *)segmentedView3 52 | { 53 | if (!_segmentedView3) { 54 | _segmentedView3 = [TCSegmentedView segmentedWithActiveItems:@[@"Step 01",@"Step 02", @"Step 03"] normalItems:@[@"😀",@"😂😂",@"😍😍😍"] frame:CGRectMake((self.view.frame.size.width - 240)/2, 260, 240, 36)]; 55 | [_segmentedView3 setBackgroundColor:[UIColor clearColor]]; 56 | [_segmentedView3 setNormalColor:[UIColor blackColor] font:AS_FONT_SF_TEXT_MEDIUM(12)]; 57 | [_segmentedView3 setSelectedColor:[UIColor whiteColor] font:AS_FONT_SF_TEXT_BOLD(14)]; 58 | _segmentedView3.backgroundNormalColor = [UIColor lightGrayColor]; 59 | _segmentedView3.backgroundActiveColor = [UIColor blueColor]; 60 | _segmentedView3.dashLineColor = [UIColor blackColor]; 61 | _segmentedView3.magirn = 8; 62 | _segmentedView3.delegate = self; 63 | } 64 | return _segmentedView3; 65 | } 66 | 67 | ``` 68 | 69 | #### License 70 | This project is released under the Apache 2.0 License. 71 | -------------------------------------------------------------------------------- /TCSegmentedView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 4C0D4B581F60313000ADF1E9 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C0D4B571F60313000ADF1E9 /* AppDelegate.m */; }; 11 | 4C0D4B5B1F60313000ADF1E9 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C0D4B5A1F60313000ADF1E9 /* ViewController.m */; }; 12 | 4C0D4B601F60313000ADF1E9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4C0D4B5F1F60313000ADF1E9 /* Assets.xcassets */; }; 13 | 4C0D4B661F60313000ADF1E9 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C0D4B651F60313000ADF1E9 /* main.m */; }; 14 | 4CB65A951F6037D100898467 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4CB65A941F6037D100898467 /* Main.storyboard */; }; 15 | 4CB65A991F60380600898467 /* TCSegmentedView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CB65A981F60380600898467 /* TCSegmentedView.m */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | 4C0D4B531F60313000ADF1E9 /* TCSegmentedView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TCSegmentedView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | 4C0D4B561F60313000ADF1E9 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 21 | 4C0D4B571F60313000ADF1E9 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 22 | 4C0D4B591F60313000ADF1E9 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 23 | 4C0D4B5A1F60313000ADF1E9 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 24 | 4C0D4B5F1F60313000ADF1E9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 25 | 4C0D4B641F60313000ADF1E9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 26 | 4C0D4B651F60313000ADF1E9 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 27 | 4CB65A941F6037D100898467 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = ""; }; 28 | 4CB65A971F60380600898467 /* TCSegmentedView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TCSegmentedView.h; sourceTree = ""; }; 29 | 4CB65A981F60380600898467 /* TCSegmentedView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TCSegmentedView.m; sourceTree = ""; }; 30 | /* End PBXFileReference section */ 31 | 32 | /* Begin PBXFrameworksBuildPhase section */ 33 | 4C0D4B501F60313000ADF1E9 /* Frameworks */ = { 34 | isa = PBXFrameworksBuildPhase; 35 | buildActionMask = 2147483647; 36 | files = ( 37 | ); 38 | runOnlyForDeploymentPostprocessing = 0; 39 | }; 40 | /* End PBXFrameworksBuildPhase section */ 41 | 42 | /* Begin PBXGroup section */ 43 | 4C0D4B4A1F60313000ADF1E9 = { 44 | isa = PBXGroup; 45 | children = ( 46 | 4C0D4B551F60313000ADF1E9 /* TCSegmentedView */, 47 | 4C0D4B541F60313000ADF1E9 /* Products */, 48 | ); 49 | sourceTree = ""; 50 | }; 51 | 4C0D4B541F60313000ADF1E9 /* Products */ = { 52 | isa = PBXGroup; 53 | children = ( 54 | 4C0D4B531F60313000ADF1E9 /* TCSegmentedView.app */, 55 | ); 56 | name = Products; 57 | sourceTree = ""; 58 | }; 59 | 4C0D4B551F60313000ADF1E9 /* TCSegmentedView */ = { 60 | isa = PBXGroup; 61 | children = ( 62 | 4CB65A961F60380600898467 /* TCSegmentedView */, 63 | 4C0D4B561F60313000ADF1E9 /* AppDelegate.h */, 64 | 4C0D4B571F60313000ADF1E9 /* AppDelegate.m */, 65 | 4C0D4B591F60313000ADF1E9 /* ViewController.h */, 66 | 4C0D4B5A1F60313000ADF1E9 /* ViewController.m */, 67 | 4CB65A941F6037D100898467 /* Main.storyboard */, 68 | 4C0D4B5F1F60313000ADF1E9 /* Assets.xcassets */, 69 | 4C0D4B641F60313000ADF1E9 /* Info.plist */, 70 | 4C0D4B651F60313000ADF1E9 /* main.m */, 71 | ); 72 | path = TCSegmentedView; 73 | sourceTree = ""; 74 | }; 75 | 4CB65A961F60380600898467 /* TCSegmentedView */ = { 76 | isa = PBXGroup; 77 | children = ( 78 | 4CB65A971F60380600898467 /* TCSegmentedView.h */, 79 | 4CB65A981F60380600898467 /* TCSegmentedView.m */, 80 | ); 81 | path = TCSegmentedView; 82 | sourceTree = ""; 83 | }; 84 | /* End PBXGroup section */ 85 | 86 | /* Begin PBXNativeTarget section */ 87 | 4C0D4B521F60313000ADF1E9 /* TCSegmentedView */ = { 88 | isa = PBXNativeTarget; 89 | buildConfigurationList = 4C0D4B691F60313000ADF1E9 /* Build configuration list for PBXNativeTarget "TCSegmentedView" */; 90 | buildPhases = ( 91 | 4C0D4B4F1F60313000ADF1E9 /* Sources */, 92 | 4C0D4B501F60313000ADF1E9 /* Frameworks */, 93 | 4C0D4B511F60313000ADF1E9 /* Resources */, 94 | ); 95 | buildRules = ( 96 | ); 97 | dependencies = ( 98 | ); 99 | name = TCSegmentedView; 100 | productName = TCSegmentedView; 101 | productReference = 4C0D4B531F60313000ADF1E9 /* TCSegmentedView.app */; 102 | productType = "com.apple.product-type.application"; 103 | }; 104 | /* End PBXNativeTarget section */ 105 | 106 | /* Begin PBXProject section */ 107 | 4C0D4B4B1F60313000ADF1E9 /* Project object */ = { 108 | isa = PBXProject; 109 | attributes = { 110 | LastUpgradeCheck = 0900; 111 | ORGANIZATIONNAME = Sam; 112 | TargetAttributes = { 113 | 4C0D4B521F60313000ADF1E9 = { 114 | CreatedOnToolsVersion = 9.0; 115 | ProvisioningStyle = Automatic; 116 | }; 117 | }; 118 | }; 119 | buildConfigurationList = 4C0D4B4E1F60313000ADF1E9 /* Build configuration list for PBXProject "TCSegmentedView" */; 120 | compatibilityVersion = "Xcode 8.0"; 121 | developmentRegion = en; 122 | hasScannedForEncodings = 0; 123 | knownRegions = ( 124 | en, 125 | Base, 126 | ); 127 | mainGroup = 4C0D4B4A1F60313000ADF1E9; 128 | productRefGroup = 4C0D4B541F60313000ADF1E9 /* Products */; 129 | projectDirPath = ""; 130 | projectRoot = ""; 131 | targets = ( 132 | 4C0D4B521F60313000ADF1E9 /* TCSegmentedView */, 133 | ); 134 | }; 135 | /* End PBXProject section */ 136 | 137 | /* Begin PBXResourcesBuildPhase section */ 138 | 4C0D4B511F60313000ADF1E9 /* Resources */ = { 139 | isa = PBXResourcesBuildPhase; 140 | buildActionMask = 2147483647; 141 | files = ( 142 | 4C0D4B601F60313000ADF1E9 /* Assets.xcassets in Resources */, 143 | 4CB65A951F6037D100898467 /* Main.storyboard in Resources */, 144 | ); 145 | runOnlyForDeploymentPostprocessing = 0; 146 | }; 147 | /* End PBXResourcesBuildPhase section */ 148 | 149 | /* Begin PBXSourcesBuildPhase section */ 150 | 4C0D4B4F1F60313000ADF1E9 /* Sources */ = { 151 | isa = PBXSourcesBuildPhase; 152 | buildActionMask = 2147483647; 153 | files = ( 154 | 4C0D4B5B1F60313000ADF1E9 /* ViewController.m in Sources */, 155 | 4C0D4B661F60313000ADF1E9 /* main.m in Sources */, 156 | 4CB65A991F60380600898467 /* TCSegmentedView.m in Sources */, 157 | 4C0D4B581F60313000ADF1E9 /* AppDelegate.m in Sources */, 158 | ); 159 | runOnlyForDeploymentPostprocessing = 0; 160 | }; 161 | /* End PBXSourcesBuildPhase section */ 162 | 163 | /* Begin XCBuildConfiguration section */ 164 | 4C0D4B671F60313000ADF1E9 /* Debug */ = { 165 | isa = XCBuildConfiguration; 166 | buildSettings = { 167 | ALWAYS_SEARCH_USER_PATHS = NO; 168 | CLANG_ANALYZER_NONNULL = YES; 169 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 170 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 171 | CLANG_CXX_LIBRARY = "libc++"; 172 | CLANG_ENABLE_MODULES = YES; 173 | CLANG_ENABLE_OBJC_ARC = YES; 174 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 175 | CLANG_WARN_BOOL_CONVERSION = YES; 176 | CLANG_WARN_COMMA = YES; 177 | CLANG_WARN_CONSTANT_CONVERSION = YES; 178 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 179 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 180 | CLANG_WARN_EMPTY_BODY = YES; 181 | CLANG_WARN_ENUM_CONVERSION = YES; 182 | CLANG_WARN_INFINITE_RECURSION = YES; 183 | CLANG_WARN_INT_CONVERSION = YES; 184 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 185 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 186 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 187 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 188 | CLANG_WARN_STRICT_PROTOTYPES = YES; 189 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 190 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 191 | CLANG_WARN_UNREACHABLE_CODE = YES; 192 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 193 | CODE_SIGN_IDENTITY = "iPhone Developer"; 194 | COPY_PHASE_STRIP = NO; 195 | DEBUG_INFORMATION_FORMAT = dwarf; 196 | ENABLE_STRICT_OBJC_MSGSEND = YES; 197 | ENABLE_TESTABILITY = YES; 198 | GCC_C_LANGUAGE_STANDARD = gnu11; 199 | GCC_DYNAMIC_NO_PIC = NO; 200 | GCC_NO_COMMON_BLOCKS = YES; 201 | GCC_OPTIMIZATION_LEVEL = 0; 202 | GCC_PREPROCESSOR_DEFINITIONS = ( 203 | "DEBUG=1", 204 | "$(inherited)", 205 | ); 206 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 207 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 208 | GCC_WARN_UNDECLARED_SELECTOR = YES; 209 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 210 | GCC_WARN_UNUSED_FUNCTION = YES; 211 | GCC_WARN_UNUSED_VARIABLE = YES; 212 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 213 | MTL_ENABLE_DEBUG_INFO = YES; 214 | ONLY_ACTIVE_ARCH = YES; 215 | SDKROOT = iphoneos; 216 | }; 217 | name = Debug; 218 | }; 219 | 4C0D4B681F60313000ADF1E9 /* Release */ = { 220 | isa = XCBuildConfiguration; 221 | buildSettings = { 222 | ALWAYS_SEARCH_USER_PATHS = NO; 223 | CLANG_ANALYZER_NONNULL = YES; 224 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 225 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 226 | CLANG_CXX_LIBRARY = "libc++"; 227 | CLANG_ENABLE_MODULES = YES; 228 | CLANG_ENABLE_OBJC_ARC = YES; 229 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 230 | CLANG_WARN_BOOL_CONVERSION = YES; 231 | CLANG_WARN_COMMA = YES; 232 | CLANG_WARN_CONSTANT_CONVERSION = YES; 233 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 234 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 235 | CLANG_WARN_EMPTY_BODY = YES; 236 | CLANG_WARN_ENUM_CONVERSION = YES; 237 | CLANG_WARN_INFINITE_RECURSION = YES; 238 | CLANG_WARN_INT_CONVERSION = YES; 239 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 240 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 241 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 242 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 243 | CLANG_WARN_STRICT_PROTOTYPES = YES; 244 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 245 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 246 | CLANG_WARN_UNREACHABLE_CODE = YES; 247 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 248 | CODE_SIGN_IDENTITY = "iPhone Developer"; 249 | COPY_PHASE_STRIP = NO; 250 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 251 | ENABLE_NS_ASSERTIONS = NO; 252 | ENABLE_STRICT_OBJC_MSGSEND = YES; 253 | GCC_C_LANGUAGE_STANDARD = gnu11; 254 | GCC_NO_COMMON_BLOCKS = YES; 255 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 256 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 257 | GCC_WARN_UNDECLARED_SELECTOR = YES; 258 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 259 | GCC_WARN_UNUSED_FUNCTION = YES; 260 | GCC_WARN_UNUSED_VARIABLE = YES; 261 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 262 | MTL_ENABLE_DEBUG_INFO = NO; 263 | SDKROOT = iphoneos; 264 | VALIDATE_PRODUCT = YES; 265 | }; 266 | name = Release; 267 | }; 268 | 4C0D4B6A1F60313000ADF1E9 /* Debug */ = { 269 | isa = XCBuildConfiguration; 270 | buildSettings = { 271 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 272 | CODE_SIGN_STYLE = Automatic; 273 | DEVELOPMENT_TEAM = W336V3LYMS; 274 | INFOPLIST_FILE = TCSegmentedView/Info.plist; 275 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 276 | PRODUCT_BUNDLE_IDENTIFIER = com.tccreation.TCSegmentedView; 277 | PRODUCT_NAME = "$(TARGET_NAME)"; 278 | TARGETED_DEVICE_FAMILY = "1,2"; 279 | }; 280 | name = Debug; 281 | }; 282 | 4C0D4B6B1F60313000ADF1E9 /* Release */ = { 283 | isa = XCBuildConfiguration; 284 | buildSettings = { 285 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 286 | CODE_SIGN_STYLE = Automatic; 287 | DEVELOPMENT_TEAM = W336V3LYMS; 288 | INFOPLIST_FILE = TCSegmentedView/Info.plist; 289 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 290 | PRODUCT_BUNDLE_IDENTIFIER = com.tccreation.TCSegmentedView; 291 | PRODUCT_NAME = "$(TARGET_NAME)"; 292 | TARGETED_DEVICE_FAMILY = "1,2"; 293 | }; 294 | name = Release; 295 | }; 296 | /* End XCBuildConfiguration section */ 297 | 298 | /* Begin XCConfigurationList section */ 299 | 4C0D4B4E1F60313000ADF1E9 /* Build configuration list for PBXProject "TCSegmentedView" */ = { 300 | isa = XCConfigurationList; 301 | buildConfigurations = ( 302 | 4C0D4B671F60313000ADF1E9 /* Debug */, 303 | 4C0D4B681F60313000ADF1E9 /* Release */, 304 | ); 305 | defaultConfigurationIsVisible = 0; 306 | defaultConfigurationName = Release; 307 | }; 308 | 4C0D4B691F60313000ADF1E9 /* Build configuration list for PBXNativeTarget "TCSegmentedView" */ = { 309 | isa = XCConfigurationList; 310 | buildConfigurations = ( 311 | 4C0D4B6A1F60313000ADF1E9 /* Debug */, 312 | 4C0D4B6B1F60313000ADF1E9 /* Release */, 313 | ); 314 | defaultConfigurationIsVisible = 0; 315 | defaultConfigurationName = Release; 316 | }; 317 | /* End XCConfigurationList section */ 318 | }; 319 | rootObject = 4C0D4B4B1F60313000ADF1E9 /* Project object */; 320 | } 321 | -------------------------------------------------------------------------------- /TCSegmentedView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TCSegmentedView.xcodeproj/project.xcworkspace/xcuserdata/os.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuongtrh/TCSegmentedView/7f2376117440de88e55b76d33634fe06981efeb1/TCSegmentedView.xcodeproj/project.xcworkspace/xcuserdata/os.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /TCSegmentedView.xcodeproj/xcuserdata/os.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /TCSegmentedView.xcodeproj/xcuserdata/os.xcuserdatad/xcschemes/TCSegmentedView.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /TCSegmentedView.xcodeproj/xcuserdata/os.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | TCSegmentedView.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 4C0D4B521F60313000ADF1E9 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /TCSegmentedView/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // TCSegmentedView 4 | // 5 | // Created by Sam on 9/6/17. 6 | // Copyright © 2017 Sam. 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 | -------------------------------------------------------------------------------- /TCSegmentedView/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // TCSegmentedView 4 | // 5 | // Created by Sam on 9/6/17. 6 | // Copyright © 2017 Sam. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | 24 | - (void)applicationWillResignActive:(UIApplication *)application { 25 | // 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. 26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 27 | } 28 | 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application { 31 | // 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. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application { 37 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 38 | } 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 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /TCSegmentedView/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | } 88 | ], 89 | "info" : { 90 | "version" : 1, 91 | "author" : "xcode" 92 | } 93 | } -------------------------------------------------------------------------------- /TCSegmentedView/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /TCSegmentedView/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /TCSegmentedView/TCSegmentedView/TCSegmentedView.h: -------------------------------------------------------------------------------- 1 | // 2 | // TCSegmentedView.h 3 | // TCSegmentedView 4 | // 5 | // Created by Sam on 9/6/17. 6 | // Copyright © 2017 Sam. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class TCSegmentedView; 12 | @protocol TCSegmentedViewDelegate 13 | 14 | -(void)onChangeItemAtIdex:(TCSegmentedView*)view index:(NSUInteger)index; 15 | 16 | @end 17 | @interface TCSegmentedView : UIView 18 | 19 | +(instancetype)segmentedWithActiveItems:(NSArray *)activeItems normalItems:(NSArray*)normalItems frame:(CGRect)frame; 20 | 21 | @property(nonatomic, weak) id delegate; 22 | 23 | - (void)setNormalColor:(UIColor *)color font:(UIFont *)font; 24 | - (void)setSelectedColor:(UIColor *)color font:(UIFont *)font; 25 | - (void)setCurrentIndex:(NSInteger)currentIndex; 26 | 27 | @property(nonatomic, assign) CGFloat magirn; 28 | @property(nonatomic, strong) UIColor *backgroundNormalColor; 29 | @property(nonatomic, strong) UIColor *backgroundActiveColor; 30 | @property(nonatomic, strong) UIColor *dashLineColor; 31 | 32 | @end 33 | 34 | -------------------------------------------------------------------------------- /TCSegmentedView/TCSegmentedView/TCSegmentedView.m: -------------------------------------------------------------------------------- 1 | // 2 | // TCSegmentedView.m 3 | // TCSegmentedView 4 | // 5 | // Created by Sam on 9/6/17. 6 | // Copyright © 2017 Sam. All rights reserved. 7 | // 8 | 9 | #import "TCSegmentedView.h" 10 | 11 | @interface TCSegmentedView() 12 | 13 | @property(nonatomic, strong) NSMutableArray *buttons; 14 | 15 | @property(nonatomic, strong) NSArray *normalItems; 16 | @property(nonatomic, strong) NSArray *activeItems; 17 | 18 | 19 | @property(nonatomic, strong) UIFont *normalFont; 20 | @property(nonatomic, strong) UIFont *activeFont; 21 | 22 | @property(nonatomic, strong) UIColor *normalColor; 23 | @property(nonatomic, strong) UIColor *activeColor; 24 | 25 | 26 | @property(nonatomic, assign) NSInteger currentIndex; 27 | @property(nonatomic, strong) CAShapeLayer *dashLine; 28 | @end 29 | 30 | @implementation TCSegmentedView 31 | 32 | 33 | +(instancetype)segmentedWithActiveItems:(NSArray *)activeItems normalItems:(NSArray*)normalItems frame:(CGRect)frame 34 | { 35 | assert([activeItems count] == [normalItems count]); 36 | 37 | TCSegmentedView *segmented = [[TCSegmentedView alloc] initWithFrame:frame]; 38 | segmented.normalItems = normalItems; 39 | segmented.activeItems = activeItems; 40 | [segmented setupUI]; 41 | 42 | return segmented; 43 | } 44 | -(instancetype)initWithFrame:(CGRect)frame 45 | { 46 | self = [super initWithFrame:frame]; 47 | if (self) { 48 | self.normalFont = [UIFont systemFontOfSize:13]; 49 | self.activeFont = [UIFont systemFontOfSize:13]; 50 | self.normalColor = [UIColor blackColor]; 51 | self.activeColor = [UIColor whiteColor]; 52 | } 53 | return self; 54 | } 55 | 56 | -(void)didMoveToSuperview 57 | { 58 | [super didMoveToSuperview]; 59 | 60 | if (self.superview) { 61 | [self setNeedsDisplay]; 62 | } 63 | } 64 | #pragma mark - Helper 65 | -(void)setupUI 66 | { 67 | //Setup default 68 | _magirn = 4; 69 | _backgroundActiveColor = [UIColor darkGrayColor]; 70 | _backgroundNormalColor = [UIColor lightGrayColor]; 71 | _dashLineColor = [UIColor blackColor]; 72 | 73 | //Init array button 74 | self.buttons = [NSMutableArray new]; 75 | CGFloat itemWith = self.frame.size.width/[self.normalItems count]; 76 | 77 | for (int i = 0 ; i < [self.normalItems count]; i++) { 78 | UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(i*itemWith, 0, itemWith, self.frame.size.height)]; 79 | [button setTitle:self.normalItems[i] forState:UIControlStateNormal]; 80 | [button setTitle:self.activeItems[i] forState:UIControlStateSelected]; 81 | button.layer.cornerRadius = self.frame.size.height/2; 82 | button.layer.masksToBounds = YES; 83 | [button addTarget:self action:@selector(onItemChange:) forControlEvents:UIControlEventTouchUpInside]; 84 | 85 | [self.buttons addObject:button]; 86 | [self addSubview:button]; 87 | } 88 | 89 | //Add dash line 90 | [self addDashedBorder:self.dashLineColor]; 91 | 92 | [self updateUI]; 93 | } 94 | -(void)addDashedBorder:(UIColor*)strokeColor { 95 | [self layoutIfNeeded]; 96 | 97 | self.dashLine = [CAShapeLayer layer]; 98 | UIBezierPath *linePath = [UIBezierPath bezierPath]; 99 | 100 | [self.dashLine setStrokeColor:strokeColor.CGColor]; 101 | [self.dashLine setLineWidth:1.0f]; 102 | [self.dashLine setLineJoin:kCALineJoinRound]; 103 | [self.dashLine setLineDashPattern:@[@2,@2]]; 104 | self.dashLine.fillColor = nil; 105 | self.dashLine.opacity = 1.0; 106 | 107 | UIButton *firstSegment = [self.buttons firstObject]; 108 | UIButton *lastSegment = [self.buttons lastObject]; 109 | 110 | [linePath moveToPoint: firstSegment.center]; 111 | [linePath addLineToPoint:lastSegment.center]; 112 | 113 | self.dashLine.path = linePath.CGPath; 114 | 115 | [self.layer insertSublayer:self.dashLine atIndex:0]; 116 | } 117 | 118 | 119 | -(void)updateUI 120 | { 121 | UIButton *button; 122 | CGFloat itemWith = self.frame.size.width/[self.normalItems count]; 123 | 124 | for (int i = 0; i < [self.buttons count] ; i++) { 125 | button = self.buttons[i]; 126 | 127 | [button setSelected:i == self.currentIndex]; 128 | [button setTitleColor:self.normalColor forState:UIControlStateNormal]; 129 | [button setTitleColor:self.activeColor forState:UIControlStateSelected]; 130 | [button.titleLabel setFont:button.isSelected?self.activeFont:self.normalFont]; 131 | [button setBackgroundColor:button.isSelected?self.backgroundActiveColor:self.backgroundNormalColor]; 132 | 133 | [UIView animateWithDuration:0.12*(i+1) delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 134 | CGRect rect = button.frame; 135 | 136 | 137 | if (i == self.currentIndex) { 138 | 139 | CGSize textSize = [self.activeItems[i] sizeWithAttributes:@{NSFontAttributeName:self.activeFont}]; 140 | 141 | rect.origin.x = i*itemWith; 142 | rect.size.width = textSize.width + self.magirn*2; 143 | }else{ 144 | if (self.currentIndex < i) { 145 | rect.origin.x = i*itemWith+itemWith/2; 146 | }else{ 147 | rect.origin.x = i*itemWith; 148 | } 149 | rect.size.width = itemWith/2 + self.magirn*2; 150 | } 151 | button.frame = rect; 152 | } completion:nil]; 153 | } 154 | } 155 | 156 | #pragma mark - Properties 157 | - (void)setNormalColor:(UIColor *)color font:(UIFont *)font { 158 | _normalFont = font; 159 | _normalColor = color; 160 | [self updateUI]; 161 | } 162 | 163 | - (void)setSelectedColor:(UIColor *)color font:(UIFont *)font { 164 | _activeFont = font; 165 | _activeColor = color; 166 | [self updateUI]; 167 | } 168 | -(void)setCurrentIndex:(NSInteger)currentIndex 169 | { 170 | _currentIndex = currentIndex; 171 | [self updateUI]; 172 | } 173 | -(void)setBackgroundActiveColor:(UIColor *)backgroundActiveColor 174 | { 175 | _backgroundActiveColor = backgroundActiveColor; 176 | [self updateUI]; 177 | } 178 | -(void)setBackgroundNormalColor:(UIColor *)backgroundNormalColor 179 | { 180 | _backgroundNormalColor = backgroundNormalColor; 181 | [self updateUI]; 182 | } 183 | -(void)setDashLineColor:(UIColor *)dashLineColor 184 | { 185 | [self.dashLine setStrokeColor:dashLineColor.CGColor]; 186 | } 187 | -(void)setMagirn:(CGFloat)magirn 188 | { 189 | _magirn = magirn; 190 | [self updateUI]; 191 | } 192 | #pragma mark - Actions 193 | -(void)onItemChange:(UIButton*)button 194 | { 195 | self.currentIndex = [self.buttons indexOfObject:button]; 196 | if (self.delegate && [self.delegate respondsToSelector:@selector(onChangeItemAtIdex:index:)]) { 197 | [self.delegate onChangeItemAtIdex:self index:self.currentIndex]; 198 | } 199 | 200 | } 201 | @end 202 | -------------------------------------------------------------------------------- /TCSegmentedView/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // TCSegmentedView 4 | // 5 | // Created by Sam on 9/6/17. 6 | // Copyright © 2017 Sam. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /TCSegmentedView/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // TCSegmentedView 4 | // 5 | // Created by Sam on 9/6/17. 6 | // Copyright © 2017 Sam. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "TCSegmentedView.h" 11 | 12 | #define AS_FONT_SF_TEXT_REGULAR(s) [UIFont fontWithName:@"HelveticaNeue-Regular" size:s] 13 | #define AS_FONT_SF_TEXT_MEDIUM(s) [UIFont fontWithName:@"HelveticaNeue-Medium" size:s] 14 | #define AS_FONT_SF_TEXT_BOLD(s) [UIFont fontWithName:@"HelveticaNeue-Bold" size:s] 15 | 16 | 17 | @interface ViewController () 18 | 19 | @property(nonatomic, strong) TCSegmentedView *segmentedView1; 20 | @property(nonatomic, strong) TCSegmentedView *segmentedView2; 21 | @property(nonatomic, strong) TCSegmentedView *segmentedView3; 22 | 23 | 24 | @end 25 | 26 | @implementation ViewController 27 | 28 | - (void)viewDidLoad { 29 | [super viewDidLoad]; 30 | // Do any additional setup after loading the view, typically from a nib. 31 | 32 | [self.view addSubview:self.segmentedView1]; 33 | [self.view addSubview:self.segmentedView2]; 34 | [self.view addSubview:self.segmentedView3]; 35 | 36 | } 37 | 38 | 39 | - (void)didReceiveMemoryWarning { 40 | [super didReceiveMemoryWarning]; 41 | // Dispose of any resources that can be recreated. 42 | } 43 | 44 | #pragma mark - Helper 45 | -(TCSegmentedView *)segmentedView1 46 | { 47 | if (!_segmentedView1) { 48 | _segmentedView1 = [TCSegmentedView segmentedWithActiveItems:@[@"01. Segment 1",@"02. Segment 2", @"03. Segment 3", @"04. Segment 4"] normalItems:@[@"01",@"02",@"03", @"04"] frame:CGRectMake(16, 60, self.view.frame.size.width - 32, 30)]; 49 | [_segmentedView1 setBackgroundColor:[UIColor clearColor]]; 50 | [_segmentedView1 setNormalColor:[UIColor whiteColor] font:AS_FONT_SF_TEXT_MEDIUM(14)]; 51 | [_segmentedView1 setSelectedColor:[UIColor whiteColor] font:AS_FONT_SF_TEXT_MEDIUM(14)]; 52 | 53 | _segmentedView1.delegate = self; 54 | } 55 | return _segmentedView1; 56 | } 57 | 58 | -(TCSegmentedView *)segmentedView2 59 | { 60 | if (!_segmentedView2) { 61 | _segmentedView2 = [TCSegmentedView segmentedWithActiveItems:@[@"01. Address",@"02. Basic Info", @"03. Photos"] normalItems:@[@"1",@"2",@"3"] frame:CGRectMake((self.view.frame.size.width - 240)/2, 160, 240, 30)]; 62 | [_segmentedView2 setBackgroundColor:[UIColor clearColor]]; 63 | [_segmentedView2 setNormalColor:[UIColor whiteColor] font:AS_FONT_SF_TEXT_REGULAR(12)]; 64 | [_segmentedView2 setSelectedColor:[UIColor whiteColor] font:AS_FONT_SF_TEXT_BOLD(14)]; 65 | _segmentedView2.backgroundNormalColor = [UIColor brownColor]; 66 | _segmentedView2.backgroundActiveColor = [UIColor redColor]; 67 | _segmentedView2.dashLineColor = [UIColor blueColor]; 68 | 69 | _segmentedView2.delegate = self; 70 | } 71 | return _segmentedView2; 72 | } 73 | 74 | -(TCSegmentedView *)segmentedView3 75 | { 76 | if (!_segmentedView3) { 77 | _segmentedView3 = [TCSegmentedView segmentedWithActiveItems:@[@"Step 01",@"Step 02", @"Step 03"] normalItems:@[@"😀",@"😂😂",@"😍😍😍"] frame:CGRectMake((self.view.frame.size.width - 240)/2, 260, 240, 36)]; 78 | [_segmentedView3 setBackgroundColor:[UIColor clearColor]]; 79 | [_segmentedView3 setNormalColor:[UIColor blackColor] font:AS_FONT_SF_TEXT_MEDIUM(12)]; 80 | [_segmentedView3 setSelectedColor:[UIColor whiteColor] font:AS_FONT_SF_TEXT_BOLD(14)]; 81 | _segmentedView3.backgroundNormalColor = [UIColor lightGrayColor]; 82 | _segmentedView3.backgroundActiveColor = [UIColor blueColor]; 83 | _segmentedView3.dashLineColor = [UIColor blackColor]; 84 | _segmentedView3.magirn = 8; 85 | _segmentedView3.delegate = self; 86 | } 87 | return _segmentedView3; 88 | } 89 | 90 | #pragma mark - TCSegmentedViewDelegate 91 | -(void)onChangeItemAtIdex:(TCSegmentedView*)view index:(NSUInteger)index 92 | { 93 | NSLog(@"Current index:%tu",index); 94 | } 95 | 96 | 97 | @end 98 | -------------------------------------------------------------------------------- /TCSegmentedView/demo/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuongtrh/TCSegmentedView/7f2376117440de88e55b76d33634fe06981efeb1/TCSegmentedView/demo/demo.gif -------------------------------------------------------------------------------- /TCSegmentedView/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // TCSegmentedView 4 | // 5 | // Created by Sam on 9/6/17. 6 | // Copyright © 2017 Sam. 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 | --------------------------------------------------------------------------------