├── LICENSE ├── README.md ├── VOSegmentedControl.podspec ├── VOSegmentedControlDemo.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── VOSegmentedControlDemo.xccheckout │ └── xcuserdata │ │ └── Valo.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── Valo.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── VOSegmentedControlDemo.xcscheme │ └── xcschememanagement.plist ├── VOSegmentedControlDemo ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── Images.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── close.imageset │ │ ├── Contents.json │ │ └── close@2x.png │ └── open.imageset │ │ ├── Contents.json │ │ └── open@2x.png ├── Info.plist ├── VOSegmentedControl │ ├── VOContentLayer.h │ ├── VOContentLayer.m │ ├── VOIndicatorAnimation.h │ ├── VOIndicatorAnimation.m │ ├── VOSegment.h │ ├── VOSegment.m │ ├── VOSegmentedControl.h │ └── VOSegmentedControl.m ├── ViewController.h ├── ViewController.m └── main.m └── VOSegmentedControlDemoTests ├── Info.plist └── VOSegmentedControlDemoTests.m /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VOSegmentedControl 2 | [![License Apache](http://img.shields.io/cocoapods/l/VOSegmentedControl.svg?style=flat)](https://raw.githubusercontent.com/pozi119/VOSegmentedControlDemo/master/LICENSE)  3 | [![CocoaPods](http://img.shields.io/cocoapods/v/VOSegmentedControl.svg?style=flat)](http://cocoapods.org/?q=VOSegmentedControlDemo)  4 | [![CocoaPods](http://img.shields.io/cocoapods/p/VOSegmentedControl.svg?style=flat)](http://cocoapods.org/?q=VOSegmentedControlDemo)  5 | [![Support](https://img.shields.io/badge/support-iOS%207%2B%20-blue.svg?style=flat)](https://www.apple.com/nl/ios/)  6 | [![Build Status](https://travis-ci.org/pozi119/VOSegmentedControlDemo.svg?branch=master)](https://travis-ci.org/pozi119/VOSegmentedControlDemo) 7 | 8 | #更新 9 | 2016.5.4 添加cocoapods支持 10 | 11 | #安装 12 | cocoapods导入: 13 | ```ruby 14 | pod 'VOSegmentedControl' 15 | ``` 16 | 手动安装: 17 | 将 ```VOSegmentedControlDemo\VOSegmentedControl``` 文件夹拖入项目之中. 18 | 19 | #使用说明 20 | 1. 支持图片和文字,包含6种简单排版: 只有文字, 只有图片, 图片在上下左右 21 | 只有图片时,图片如果比分段大,则只铺满整个分段,若比分段小,则为图片大小居中 22 | 图片在左,右时,图片层为正方形, 最大边长是分段的高度, 23 | 图片在顶部或者底部时, 图片的最大高度为 分段高度 x 0.618 24 | 25 | 2. 指示器支持3种类型: 顶部线条,底部线条,方框; 可设置indicatorThickness和indicatorCornerRadius 变为圆角指示器, 当indicatorThickness = 0时, 指示器不显示 26 | 27 | 3. 指示器移动效果: 平滑移动,弹簧效果. 28 | 29 | 4. 可设置选中/未选中时文字的字体, 颜色 30 | 31 | 5. 可设置选中时的背景色,如果指示器设置成圆角的,背景也变成圆角 32 | 33 | 6. 可设置不选择任何分段 34 | 35 | 7. 指示器移动效果可以自己写: 在VOIndicatorAnimation中加相应的方法 36 | 37 | 8. 可再Storyboard中添加UIView,更改对应的Class为VOSegmentControl,在storyboard中添加keypath设置对应参数(枚举变量设置对应的NSNumber值).代码中只用设置分段内容如: 38 | 39 | self.segmentControl5.segments = @[@{VOSegmentText: @"A", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 40 | @{VOSegmentText: @"B", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 41 | @{VOSegmentText: @"C", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 42 | @{VOSegmentText: @"D", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 43 | @{VOSegmentText: @"E", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 44 | @{VOSegmentText: @"F", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 45 | @{VOSegmentText: @"G", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 46 | @{VOSegmentText: @"H", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 47 | @{VOSegmentText: @"I", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}]; 48 | 49 | -------------------------------------------------------------------------------- /VOSegmentedControl.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "VOSegmentedControl" 3 | s.version = "1.0.0" 4 | s.summary = "A segmented control with multi styles" 5 | s.homepage = "https://github.com/pozi119/VOSegmentedControlDemo" 6 | s.license = { :type => 'GPL V2.0', :file => 'LICENSE' } 7 | s.author = { "pozi119" => "pozi119@163.com" } 8 | s.platform = :ios, "7.0" 9 | s.ios.deployment_target = "7.0" 10 | s.source = { :git => "https://github.com/pozi119/VOSegmentedControlDemo.git", :tag => "1.0.0" } 11 | s.source_files = "VOSegmentedControlDemo/VOSegmentedControl", "VOSegmentedControlDemo/VOSegmentedControl/*.{h,m}" 12 | end 13 | -------------------------------------------------------------------------------- /VOSegmentedControlDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 3E1F82C81A26CAB900A0720B /* VOContentLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E1F82C71A26CAB900A0720B /* VOContentLayer.m */; }; 11 | 3E1F82CB1A26CC9C00A0720B /* VOSegment.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E1F82CA1A26CC9C00A0720B /* VOSegment.m */; }; 12 | 3E4684271A1C7F9C000C2514 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E4684261A1C7F9C000C2514 /* main.m */; }; 13 | 3E46842A1A1C7F9C000C2514 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E4684291A1C7F9C000C2514 /* AppDelegate.m */; }; 14 | 3E46842D1A1C7F9C000C2514 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E46842C1A1C7F9C000C2514 /* ViewController.m */; }; 15 | 3E4684301A1C7F9C000C2514 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3E46842E1A1C7F9C000C2514 /* Main.storyboard */; }; 16 | 3E4684321A1C7F9C000C2514 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3E4684311A1C7F9C000C2514 /* Images.xcassets */; }; 17 | 3E4684351A1C7F9C000C2514 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3E4684331A1C7F9C000C2514 /* LaunchScreen.xib */; }; 18 | 3E4684411A1C7F9C000C2514 /* VOSegmentedControlDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E4684401A1C7F9C000C2514 /* VOSegmentedControlDemoTests.m */; }; 19 | 3E46844D1A1C7FBE000C2514 /* VOSegmentedControl.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E46844C1A1C7FBE000C2514 /* VOSegmentedControl.m */; }; 20 | 3E6DD2761A2AC69B00160076 /* VOIndicatorAnimation.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E6DD2751A2AC69B00160076 /* VOIndicatorAnimation.m */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXContainerItemProxy section */ 24 | 3E46843B1A1C7F9C000C2514 /* PBXContainerItemProxy */ = { 25 | isa = PBXContainerItemProxy; 26 | containerPortal = 3E4684191A1C7F9C000C2514 /* Project object */; 27 | proxyType = 1; 28 | remoteGlobalIDString = 3E4684201A1C7F9C000C2514; 29 | remoteInfo = VOSegmentedControlDemo; 30 | }; 31 | /* End PBXContainerItemProxy section */ 32 | 33 | /* Begin PBXFileReference section */ 34 | 3E1F82C61A26CAB900A0720B /* VOContentLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VOContentLayer.h; path = VOSegmentedControl/VOContentLayer.h; sourceTree = ""; }; 35 | 3E1F82C71A26CAB900A0720B /* VOContentLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VOContentLayer.m; path = VOSegmentedControl/VOContentLayer.m; sourceTree = ""; }; 36 | 3E1F82C91A26CC9C00A0720B /* VOSegment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VOSegment.h; path = VOSegmentedControl/VOSegment.h; sourceTree = ""; }; 37 | 3E1F82CA1A26CC9C00A0720B /* VOSegment.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VOSegment.m; path = VOSegmentedControl/VOSegment.m; sourceTree = ""; }; 38 | 3E4684211A1C7F9C000C2514 /* VOSegmentedControlDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = VOSegmentedControlDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 39 | 3E4684251A1C7F9C000C2514 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 40 | 3E4684261A1C7F9C000C2514 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 41 | 3E4684281A1C7F9C000C2514 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 42 | 3E4684291A1C7F9C000C2514 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 43 | 3E46842B1A1C7F9C000C2514 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 44 | 3E46842C1A1C7F9C000C2514 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 45 | 3E46842F1A1C7F9C000C2514 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 46 | 3E4684311A1C7F9C000C2514 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 47 | 3E4684341A1C7F9C000C2514 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 48 | 3E46843A1A1C7F9C000C2514 /* VOSegmentedControlDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = VOSegmentedControlDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 49 | 3E46843F1A1C7F9C000C2514 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 50 | 3E4684401A1C7F9C000C2514 /* VOSegmentedControlDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VOSegmentedControlDemoTests.m; sourceTree = ""; }; 51 | 3E46844B1A1C7FBE000C2514 /* VOSegmentedControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VOSegmentedControl.h; path = VOSegmentedControl/VOSegmentedControl.h; sourceTree = ""; }; 52 | 3E46844C1A1C7FBE000C2514 /* VOSegmentedControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VOSegmentedControl.m; path = VOSegmentedControl/VOSegmentedControl.m; sourceTree = ""; }; 53 | 3E6DD2741A2AC69B00160076 /* VOIndicatorAnimation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VOIndicatorAnimation.h; path = VOSegmentedControl/VOIndicatorAnimation.h; sourceTree = ""; }; 54 | 3E6DD2751A2AC69B00160076 /* VOIndicatorAnimation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VOIndicatorAnimation.m; path = VOSegmentedControl/VOIndicatorAnimation.m; sourceTree = ""; }; 55 | /* End PBXFileReference section */ 56 | 57 | /* Begin PBXFrameworksBuildPhase section */ 58 | 3E46841E1A1C7F9C000C2514 /* Frameworks */ = { 59 | isa = PBXFrameworksBuildPhase; 60 | buildActionMask = 2147483647; 61 | files = ( 62 | ); 63 | runOnlyForDeploymentPostprocessing = 0; 64 | }; 65 | 3E4684371A1C7F9C000C2514 /* Frameworks */ = { 66 | isa = PBXFrameworksBuildPhase; 67 | buildActionMask = 2147483647; 68 | files = ( 69 | ); 70 | runOnlyForDeploymentPostprocessing = 0; 71 | }; 72 | /* End PBXFrameworksBuildPhase section */ 73 | 74 | /* Begin PBXGroup section */ 75 | 3E4684181A1C7F9C000C2514 = { 76 | isa = PBXGroup; 77 | children = ( 78 | 3E4684231A1C7F9C000C2514 /* VOSegmentedControlDemo */, 79 | 3E46843D1A1C7F9C000C2514 /* VOSegmentedControlDemoTests */, 80 | 3E4684221A1C7F9C000C2514 /* Products */, 81 | ); 82 | sourceTree = ""; 83 | }; 84 | 3E4684221A1C7F9C000C2514 /* Products */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | 3E4684211A1C7F9C000C2514 /* VOSegmentedControlDemo.app */, 88 | 3E46843A1A1C7F9C000C2514 /* VOSegmentedControlDemoTests.xctest */, 89 | ); 90 | name = Products; 91 | sourceTree = ""; 92 | }; 93 | 3E4684231A1C7F9C000C2514 /* VOSegmentedControlDemo */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | 3E46844A1A1C7FA4000C2514 /* VOSegmentedControl */, 97 | 3E4684281A1C7F9C000C2514 /* AppDelegate.h */, 98 | 3E4684291A1C7F9C000C2514 /* AppDelegate.m */, 99 | 3E46842B1A1C7F9C000C2514 /* ViewController.h */, 100 | 3E46842C1A1C7F9C000C2514 /* ViewController.m */, 101 | 3E46842E1A1C7F9C000C2514 /* Main.storyboard */, 102 | 3E4684311A1C7F9C000C2514 /* Images.xcassets */, 103 | 3E4684331A1C7F9C000C2514 /* LaunchScreen.xib */, 104 | 3E4684241A1C7F9C000C2514 /* Supporting Files */, 105 | ); 106 | path = VOSegmentedControlDemo; 107 | sourceTree = ""; 108 | }; 109 | 3E4684241A1C7F9C000C2514 /* Supporting Files */ = { 110 | isa = PBXGroup; 111 | children = ( 112 | 3E4684251A1C7F9C000C2514 /* Info.plist */, 113 | 3E4684261A1C7F9C000C2514 /* main.m */, 114 | ); 115 | name = "Supporting Files"; 116 | sourceTree = ""; 117 | }; 118 | 3E46843D1A1C7F9C000C2514 /* VOSegmentedControlDemoTests */ = { 119 | isa = PBXGroup; 120 | children = ( 121 | 3E4684401A1C7F9C000C2514 /* VOSegmentedControlDemoTests.m */, 122 | 3E46843E1A1C7F9C000C2514 /* Supporting Files */, 123 | ); 124 | path = VOSegmentedControlDemoTests; 125 | sourceTree = ""; 126 | }; 127 | 3E46843E1A1C7F9C000C2514 /* Supporting Files */ = { 128 | isa = PBXGroup; 129 | children = ( 130 | 3E46843F1A1C7F9C000C2514 /* Info.plist */, 131 | ); 132 | name = "Supporting Files"; 133 | sourceTree = ""; 134 | }; 135 | 3E46844A1A1C7FA4000C2514 /* VOSegmentedControl */ = { 136 | isa = PBXGroup; 137 | children = ( 138 | 3E1F82C91A26CC9C00A0720B /* VOSegment.h */, 139 | 3E1F82CA1A26CC9C00A0720B /* VOSegment.m */, 140 | 3E1F82C61A26CAB900A0720B /* VOContentLayer.h */, 141 | 3E1F82C71A26CAB900A0720B /* VOContentLayer.m */, 142 | 3E6DD2741A2AC69B00160076 /* VOIndicatorAnimation.h */, 143 | 3E6DD2751A2AC69B00160076 /* VOIndicatorAnimation.m */, 144 | 3E46844B1A1C7FBE000C2514 /* VOSegmentedControl.h */, 145 | 3E46844C1A1C7FBE000C2514 /* VOSegmentedControl.m */, 146 | ); 147 | name = VOSegmentedControl; 148 | sourceTree = ""; 149 | }; 150 | /* End PBXGroup section */ 151 | 152 | /* Begin PBXNativeTarget section */ 153 | 3E4684201A1C7F9C000C2514 /* VOSegmentedControlDemo */ = { 154 | isa = PBXNativeTarget; 155 | buildConfigurationList = 3E4684441A1C7F9C000C2514 /* Build configuration list for PBXNativeTarget "VOSegmentedControlDemo" */; 156 | buildPhases = ( 157 | 3E46841D1A1C7F9C000C2514 /* Sources */, 158 | 3E46841E1A1C7F9C000C2514 /* Frameworks */, 159 | 3E46841F1A1C7F9C000C2514 /* Resources */, 160 | ); 161 | buildRules = ( 162 | ); 163 | dependencies = ( 164 | ); 165 | name = VOSegmentedControlDemo; 166 | productName = VOSegmentedControlDemo; 167 | productReference = 3E4684211A1C7F9C000C2514 /* VOSegmentedControlDemo.app */; 168 | productType = "com.apple.product-type.application"; 169 | }; 170 | 3E4684391A1C7F9C000C2514 /* VOSegmentedControlDemoTests */ = { 171 | isa = PBXNativeTarget; 172 | buildConfigurationList = 3E4684471A1C7F9C000C2514 /* Build configuration list for PBXNativeTarget "VOSegmentedControlDemoTests" */; 173 | buildPhases = ( 174 | 3E4684361A1C7F9C000C2514 /* Sources */, 175 | 3E4684371A1C7F9C000C2514 /* Frameworks */, 176 | 3E4684381A1C7F9C000C2514 /* Resources */, 177 | ); 178 | buildRules = ( 179 | ); 180 | dependencies = ( 181 | 3E46843C1A1C7F9C000C2514 /* PBXTargetDependency */, 182 | ); 183 | name = VOSegmentedControlDemoTests; 184 | productName = VOSegmentedControlDemoTests; 185 | productReference = 3E46843A1A1C7F9C000C2514 /* VOSegmentedControlDemoTests.xctest */; 186 | productType = "com.apple.product-type.bundle.unit-test"; 187 | }; 188 | /* End PBXNativeTarget section */ 189 | 190 | /* Begin PBXProject section */ 191 | 3E4684191A1C7F9C000C2514 /* Project object */ = { 192 | isa = PBXProject; 193 | attributes = { 194 | LastUpgradeCheck = 0610; 195 | ORGANIZATIONNAME = valo; 196 | TargetAttributes = { 197 | 3E4684201A1C7F9C000C2514 = { 198 | CreatedOnToolsVersion = 6.1.1; 199 | }; 200 | 3E4684391A1C7F9C000C2514 = { 201 | CreatedOnToolsVersion = 6.1.1; 202 | TestTargetID = 3E4684201A1C7F9C000C2514; 203 | }; 204 | }; 205 | }; 206 | buildConfigurationList = 3E46841C1A1C7F9C000C2514 /* Build configuration list for PBXProject "VOSegmentedControlDemo" */; 207 | compatibilityVersion = "Xcode 3.2"; 208 | developmentRegion = English; 209 | hasScannedForEncodings = 0; 210 | knownRegions = ( 211 | en, 212 | Base, 213 | ); 214 | mainGroup = 3E4684181A1C7F9C000C2514; 215 | productRefGroup = 3E4684221A1C7F9C000C2514 /* Products */; 216 | projectDirPath = ""; 217 | projectRoot = ""; 218 | targets = ( 219 | 3E4684201A1C7F9C000C2514 /* VOSegmentedControlDemo */, 220 | 3E4684391A1C7F9C000C2514 /* VOSegmentedControlDemoTests */, 221 | ); 222 | }; 223 | /* End PBXProject section */ 224 | 225 | /* Begin PBXResourcesBuildPhase section */ 226 | 3E46841F1A1C7F9C000C2514 /* Resources */ = { 227 | isa = PBXResourcesBuildPhase; 228 | buildActionMask = 2147483647; 229 | files = ( 230 | 3E4684301A1C7F9C000C2514 /* Main.storyboard in Resources */, 231 | 3E4684351A1C7F9C000C2514 /* LaunchScreen.xib in Resources */, 232 | 3E4684321A1C7F9C000C2514 /* Images.xcassets in Resources */, 233 | ); 234 | runOnlyForDeploymentPostprocessing = 0; 235 | }; 236 | 3E4684381A1C7F9C000C2514 /* Resources */ = { 237 | isa = PBXResourcesBuildPhase; 238 | buildActionMask = 2147483647; 239 | files = ( 240 | ); 241 | runOnlyForDeploymentPostprocessing = 0; 242 | }; 243 | /* End PBXResourcesBuildPhase section */ 244 | 245 | /* Begin PBXSourcesBuildPhase section */ 246 | 3E46841D1A1C7F9C000C2514 /* Sources */ = { 247 | isa = PBXSourcesBuildPhase; 248 | buildActionMask = 2147483647; 249 | files = ( 250 | 3E46842D1A1C7F9C000C2514 /* ViewController.m in Sources */, 251 | 3E46844D1A1C7FBE000C2514 /* VOSegmentedControl.m in Sources */, 252 | 3E1F82CB1A26CC9C00A0720B /* VOSegment.m in Sources */, 253 | 3E6DD2761A2AC69B00160076 /* VOIndicatorAnimation.m in Sources */, 254 | 3E1F82C81A26CAB900A0720B /* VOContentLayer.m in Sources */, 255 | 3E46842A1A1C7F9C000C2514 /* AppDelegate.m in Sources */, 256 | 3E4684271A1C7F9C000C2514 /* main.m in Sources */, 257 | ); 258 | runOnlyForDeploymentPostprocessing = 0; 259 | }; 260 | 3E4684361A1C7F9C000C2514 /* Sources */ = { 261 | isa = PBXSourcesBuildPhase; 262 | buildActionMask = 2147483647; 263 | files = ( 264 | 3E4684411A1C7F9C000C2514 /* VOSegmentedControlDemoTests.m in Sources */, 265 | ); 266 | runOnlyForDeploymentPostprocessing = 0; 267 | }; 268 | /* End PBXSourcesBuildPhase section */ 269 | 270 | /* Begin PBXTargetDependency section */ 271 | 3E46843C1A1C7F9C000C2514 /* PBXTargetDependency */ = { 272 | isa = PBXTargetDependency; 273 | target = 3E4684201A1C7F9C000C2514 /* VOSegmentedControlDemo */; 274 | targetProxy = 3E46843B1A1C7F9C000C2514 /* PBXContainerItemProxy */; 275 | }; 276 | /* End PBXTargetDependency section */ 277 | 278 | /* Begin PBXVariantGroup section */ 279 | 3E46842E1A1C7F9C000C2514 /* Main.storyboard */ = { 280 | isa = PBXVariantGroup; 281 | children = ( 282 | 3E46842F1A1C7F9C000C2514 /* Base */, 283 | ); 284 | name = Main.storyboard; 285 | sourceTree = ""; 286 | }; 287 | 3E4684331A1C7F9C000C2514 /* LaunchScreen.xib */ = { 288 | isa = PBXVariantGroup; 289 | children = ( 290 | 3E4684341A1C7F9C000C2514 /* Base */, 291 | ); 292 | name = LaunchScreen.xib; 293 | sourceTree = ""; 294 | }; 295 | /* End PBXVariantGroup section */ 296 | 297 | /* Begin XCBuildConfiguration section */ 298 | 3E4684421A1C7F9C000C2514 /* Debug */ = { 299 | isa = XCBuildConfiguration; 300 | buildSettings = { 301 | ALWAYS_SEARCH_USER_PATHS = NO; 302 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 303 | CLANG_CXX_LIBRARY = "libc++"; 304 | CLANG_ENABLE_MODULES = YES; 305 | CLANG_ENABLE_OBJC_ARC = YES; 306 | CLANG_WARN_BOOL_CONVERSION = YES; 307 | CLANG_WARN_CONSTANT_CONVERSION = YES; 308 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 309 | CLANG_WARN_EMPTY_BODY = YES; 310 | CLANG_WARN_ENUM_CONVERSION = YES; 311 | CLANG_WARN_INT_CONVERSION = YES; 312 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 313 | CLANG_WARN_UNREACHABLE_CODE = YES; 314 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 315 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 316 | COPY_PHASE_STRIP = NO; 317 | ENABLE_STRICT_OBJC_MSGSEND = YES; 318 | GCC_C_LANGUAGE_STANDARD = gnu99; 319 | GCC_DYNAMIC_NO_PIC = NO; 320 | GCC_OPTIMIZATION_LEVEL = 0; 321 | GCC_PREPROCESSOR_DEFINITIONS = ( 322 | "DEBUG=1", 323 | "$(inherited)", 324 | ); 325 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 326 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 327 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 328 | GCC_WARN_UNDECLARED_SELECTOR = YES; 329 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 330 | GCC_WARN_UNUSED_FUNCTION = YES; 331 | GCC_WARN_UNUSED_VARIABLE = YES; 332 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 333 | MTL_ENABLE_DEBUG_INFO = YES; 334 | ONLY_ACTIVE_ARCH = YES; 335 | SDKROOT = iphoneos; 336 | }; 337 | name = Debug; 338 | }; 339 | 3E4684431A1C7F9C000C2514 /* Release */ = { 340 | isa = XCBuildConfiguration; 341 | buildSettings = { 342 | ALWAYS_SEARCH_USER_PATHS = NO; 343 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 344 | CLANG_CXX_LIBRARY = "libc++"; 345 | CLANG_ENABLE_MODULES = YES; 346 | CLANG_ENABLE_OBJC_ARC = YES; 347 | CLANG_WARN_BOOL_CONVERSION = YES; 348 | CLANG_WARN_CONSTANT_CONVERSION = YES; 349 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 350 | CLANG_WARN_EMPTY_BODY = YES; 351 | CLANG_WARN_ENUM_CONVERSION = YES; 352 | CLANG_WARN_INT_CONVERSION = YES; 353 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 354 | CLANG_WARN_UNREACHABLE_CODE = YES; 355 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 356 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 357 | COPY_PHASE_STRIP = YES; 358 | ENABLE_NS_ASSERTIONS = NO; 359 | ENABLE_STRICT_OBJC_MSGSEND = YES; 360 | GCC_C_LANGUAGE_STANDARD = gnu99; 361 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 362 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 363 | GCC_WARN_UNDECLARED_SELECTOR = YES; 364 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 365 | GCC_WARN_UNUSED_FUNCTION = YES; 366 | GCC_WARN_UNUSED_VARIABLE = YES; 367 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 368 | MTL_ENABLE_DEBUG_INFO = NO; 369 | SDKROOT = iphoneos; 370 | VALIDATE_PRODUCT = YES; 371 | }; 372 | name = Release; 373 | }; 374 | 3E4684451A1C7F9C000C2514 /* Debug */ = { 375 | isa = XCBuildConfiguration; 376 | buildSettings = { 377 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 378 | INFOPLIST_FILE = VOSegmentedControlDemo/Info.plist; 379 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 380 | PRODUCT_NAME = "$(TARGET_NAME)"; 381 | }; 382 | name = Debug; 383 | }; 384 | 3E4684461A1C7F9C000C2514 /* Release */ = { 385 | isa = XCBuildConfiguration; 386 | buildSettings = { 387 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 388 | INFOPLIST_FILE = VOSegmentedControlDemo/Info.plist; 389 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 390 | PRODUCT_NAME = "$(TARGET_NAME)"; 391 | }; 392 | name = Release; 393 | }; 394 | 3E4684481A1C7F9C000C2514 /* Debug */ = { 395 | isa = XCBuildConfiguration; 396 | buildSettings = { 397 | BUNDLE_LOADER = "$(TEST_HOST)"; 398 | FRAMEWORK_SEARCH_PATHS = ( 399 | "$(SDKROOT)/Developer/Library/Frameworks", 400 | "$(inherited)", 401 | ); 402 | GCC_PREPROCESSOR_DEFINITIONS = ( 403 | "DEBUG=1", 404 | "$(inherited)", 405 | ); 406 | INFOPLIST_FILE = VOSegmentedControlDemoTests/Info.plist; 407 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 408 | PRODUCT_NAME = "$(TARGET_NAME)"; 409 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/VOSegmentedControlDemo.app/VOSegmentedControlDemo"; 410 | }; 411 | name = Debug; 412 | }; 413 | 3E4684491A1C7F9C000C2514 /* Release */ = { 414 | isa = XCBuildConfiguration; 415 | buildSettings = { 416 | BUNDLE_LOADER = "$(TEST_HOST)"; 417 | FRAMEWORK_SEARCH_PATHS = ( 418 | "$(SDKROOT)/Developer/Library/Frameworks", 419 | "$(inherited)", 420 | ); 421 | INFOPLIST_FILE = VOSegmentedControlDemoTests/Info.plist; 422 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 423 | PRODUCT_NAME = "$(TARGET_NAME)"; 424 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/VOSegmentedControlDemo.app/VOSegmentedControlDemo"; 425 | }; 426 | name = Release; 427 | }; 428 | /* End XCBuildConfiguration section */ 429 | 430 | /* Begin XCConfigurationList section */ 431 | 3E46841C1A1C7F9C000C2514 /* Build configuration list for PBXProject "VOSegmentedControlDemo" */ = { 432 | isa = XCConfigurationList; 433 | buildConfigurations = ( 434 | 3E4684421A1C7F9C000C2514 /* Debug */, 435 | 3E4684431A1C7F9C000C2514 /* Release */, 436 | ); 437 | defaultConfigurationIsVisible = 0; 438 | defaultConfigurationName = Release; 439 | }; 440 | 3E4684441A1C7F9C000C2514 /* Build configuration list for PBXNativeTarget "VOSegmentedControlDemo" */ = { 441 | isa = XCConfigurationList; 442 | buildConfigurations = ( 443 | 3E4684451A1C7F9C000C2514 /* Debug */, 444 | 3E4684461A1C7F9C000C2514 /* Release */, 445 | ); 446 | defaultConfigurationIsVisible = 0; 447 | defaultConfigurationName = Release; 448 | }; 449 | 3E4684471A1C7F9C000C2514 /* Build configuration list for PBXNativeTarget "VOSegmentedControlDemoTests" */ = { 450 | isa = XCConfigurationList; 451 | buildConfigurations = ( 452 | 3E4684481A1C7F9C000C2514 /* Debug */, 453 | 3E4684491A1C7F9C000C2514 /* Release */, 454 | ); 455 | defaultConfigurationIsVisible = 0; 456 | defaultConfigurationName = Release; 457 | }; 458 | /* End XCConfigurationList section */ 459 | }; 460 | rootObject = 3E4684191A1C7F9C000C2514 /* Project object */; 461 | } 462 | -------------------------------------------------------------------------------- /VOSegmentedControlDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /VOSegmentedControlDemo.xcodeproj/project.xcworkspace/xcshareddata/VOSegmentedControlDemo.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | CFA8CEE9-799B-4536-8073-1421BA743DAA 9 | IDESourceControlProjectName 10 | VOSegmentedControlDemo 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | D9356A042CDA2547EFDDDE759F9118640F71F77C 14 | https://github.com/pozi119/VOSegmentedControlDemo.git 15 | 16 | IDESourceControlProjectPath 17 | VOSegmentedControlDemo.xcodeproj 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | D9356A042CDA2547EFDDDE759F9118640F71F77C 21 | ../.. 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/pozi119/VOSegmentedControlDemo.git 25 | IDESourceControlProjectVersion 26 | 111 27 | IDESourceControlProjectWCCIdentifier 28 | D9356A042CDA2547EFDDDE759F9118640F71F77C 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | D9356A042CDA2547EFDDDE759F9118640F71F77C 36 | IDESourceControlWCCName 37 | VOSegmentedControlDemo 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /VOSegmentedControlDemo.xcodeproj/project.xcworkspace/xcuserdata/Valo.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pozi119/VOSegmentedControlDemo/31becc0e5f04d2c52959474ab52f333e1b2c055c/VOSegmentedControlDemo.xcodeproj/project.xcworkspace/xcuserdata/Valo.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /VOSegmentedControlDemo.xcodeproj/xcuserdata/Valo.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 14 | 15 | 16 | 18 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /VOSegmentedControlDemo.xcodeproj/xcuserdata/Valo.xcuserdatad/xcschemes/VOSegmentedControlDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 94 | 100 | 101 | 102 | 103 | 105 | 106 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /VOSegmentedControlDemo.xcodeproj/xcuserdata/Valo.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | VOSegmentedControlDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 3E4684201A1C7F9C000C2514 16 | 17 | primary 18 | 19 | 20 | 3E4684391A1C7F9C000C2514 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /VOSegmentedControlDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // VOSegmentedControlDemo 4 | // 5 | // Created by Valo Lee on 14-11-19. 6 | // Copyright (c) 2014年 valo. 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 | -------------------------------------------------------------------------------- /VOSegmentedControlDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // VOSegmentedControlDemo 4 | // 5 | // Created by Valo Lee on 14-11-19. 6 | // Copyright (c) 2014年 valo. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /VOSegmentedControlDemo/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /VOSegmentedControlDemo/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 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /VOSegmentedControlDemo/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /VOSegmentedControlDemo/Images.xcassets/close.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x", 10 | "filename" : "close@2x.png" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /VOSegmentedControlDemo/Images.xcassets/close.imageset/close@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pozi119/VOSegmentedControlDemo/31becc0e5f04d2c52959474ab52f333e1b2c055c/VOSegmentedControlDemo/Images.xcassets/close.imageset/close@2x.png -------------------------------------------------------------------------------- /VOSegmentedControlDemo/Images.xcassets/open.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x", 10 | "filename" : "open@2x.png" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /VOSegmentedControlDemo/Images.xcassets/open.imageset/open@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pozi119/VOSegmentedControlDemo/31becc0e5f04d2c52959474ab52f333e1b2c055c/VOSegmentedControlDemo/Images.xcassets/open.imageset/open@2x.png -------------------------------------------------------------------------------- /VOSegmentedControlDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.valo.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /VOSegmentedControlDemo/VOSegmentedControl/VOContentLayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // VOContentLayer.h 3 | // VOSegmentedControlDemo 4 | // 5 | // Created by Valo Lee on 14-11-27. 6 | // Copyright (c) 2014年 valo. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VOSegment.h" 11 | 12 | #define kContentAnimationDuration 0.3 13 | 14 | typedef NS_ENUM(NSUInteger, VOContentStyle) { 15 | VOContentStyleTextAlone, // 只有文字 16 | VOContentStyleImageAlone, // 只有图片, imageLayer.size = self.bounds.size 17 | VOContentStyleImageLeft, // 图片在左侧, imageLayer为正方形, 最大边长为self.bounds.size.height 18 | VOContentStyleImageRight, // 图片在右侧, imageLayer为正方形, 最大边长为self.bounds.size.height 19 | VOContentStyleImageTop, // 图片在顶部, imageLayer高度为self.bounds.size.height * 0.618 20 | VOContentStyleImageBottom, // 图片在底部, imageLayer高度为self.bounds.size.height * 0.618 21 | }; 22 | 23 | @interface VOContentLayer : CALayer 24 | 25 | @property (nonatomic, strong) UIFont *font; 26 | @property (nonatomic, strong) UIFont *selectedFont; 27 | @property (nonatomic, strong) UIColor *textColor; 28 | @property (nonatomic, strong) UIColor *selectedTextColor; 29 | @property (nonatomic, strong) UIColor *normalBackgroundColor; 30 | @property (nonatomic, strong) UIColor *selectedbackgroundColor; 31 | 32 | @property (nonatomic, strong) VOSegment *segment; 33 | @property (nonatomic, assign) BOOL selected; 34 | @property (nonatomic, assign) BOOL clung; /** 当图片较小时,是否紧贴文字 */ 35 | @property (nonatomic, assign) UIEdgeInsets redPointInsets; /** 小红点位置,以左上角为基准 */ 36 | @property (nonatomic, assign) BOOL showRedPoint; /** 小红点位置 */ 37 | 38 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated completion: (void (^)())completion; 39 | 40 | + (instancetype)contentLayerWithFrame:(CGRect)frame 41 | contentInsets:(UIEdgeInsets)insets 42 | segment:(VOSegment *)segment 43 | contentStyle:(VOContentStyle)style; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /VOSegmentedControlDemo/VOSegmentedControl/VOContentLayer.m: -------------------------------------------------------------------------------- 1 | // 2 | // VOContentLayer.m 3 | // VOSegmentedControlDemo 4 | // 5 | // Created by Valo Lee on 14-11-27. 6 | // Copyright (c) 2014年 valo. All rights reserved. 7 | // 8 | 9 | #import "VOContentLayer.h" 10 | #define kTextImagePadding ((self.clung)?2:8) 11 | 12 | @interface VOContentLayer () 13 | 14 | @property (nonatomic, strong) CATextLayer *textLayer; 15 | @property (nonatomic, strong) CATextLayer *selectedTextLayer; 16 | @property (nonatomic, strong) CALayer *imageLayer; 17 | @property (nonatomic, strong) CALayer *selectedImageLayer; 18 | @property (nonatomic, strong) CALayer *redPointLayer; 19 | @property (nonatomic, assign) VOContentStyle contentStyle; 20 | @property (nonatomic, assign) UIEdgeInsets contentInsets; 21 | 22 | @end 23 | 24 | @implementation VOContentLayer 25 | 26 | + (instancetype)contentLayerWithFrame:(CGRect)frame 27 | contentInsets:(UIEdgeInsets)insets 28 | segment:(VOSegment *)segment 29 | contentStyle:(VOContentStyle)style{ 30 | VOContentLayer *contentLayer = [VOContentLayer layer]; 31 | contentLayer.frame = frame; 32 | contentLayer.contentInsets = insets; 33 | contentLayer.font = [UIFont systemFontOfSize:14]; 34 | contentLayer.selectedFont = contentLayer.font; 35 | contentLayer.textColor = [UIColor darkTextColor]; 36 | contentLayer.selectedTextColor = contentLayer.textColor; 37 | contentLayer.normalBackgroundColor = [UIColor clearColor]; 38 | contentLayer.selectedbackgroundColor = contentLayer.normalBackgroundColor; 39 | contentLayer.backgroundColor = contentLayer.normalBackgroundColor.CGColor; 40 | 41 | contentLayer.contentStyle = style; 42 | contentLayer.segment = segment; 43 | contentLayer.clung = YES; 44 | return contentLayer; 45 | } 46 | 47 | - (CATextLayer *)textLayer{ 48 | if (!_textLayer) { 49 | if (self.segment.text) { 50 | CATextLayer *textLayer = [CATextLayer layer]; 51 | textLayer.frame = [self textLayerFrameForSegment:self.segment.text andFont:self.font]; 52 | textLayer.backgroundColor = [UIColor clearColor].CGColor; 53 | textLayer.font = (__bridge CFTypeRef)self.font.fontName; 54 | textLayer.fontSize = self.font.pointSize; 55 | textLayer.foregroundColor = self.textColor.CGColor; 56 | textLayer.string = self.segment.text; 57 | textLayer.contentsScale = [UIScreen mainScreen].scale; 58 | _textLayer = textLayer; 59 | [self addSublayer:_textLayer]; 60 | } 61 | } 62 | return _textLayer; 63 | } 64 | 65 | - (CATextLayer *)selectedTextLayer{ 66 | if (!_selectedTextLayer) { 67 | if (self.segment.selectedText) { 68 | CATextLayer *selectedTextLayer = [CATextLayer layer]; 69 | selectedTextLayer.frame = [self textLayerFrameForSegment:self.segment.selectedText andFont:self.selectedFont]; 70 | selectedTextLayer.backgroundColor = [UIColor clearColor].CGColor; 71 | selectedTextLayer.font = (__bridge CFTypeRef)self.selectedFont.fontName; 72 | selectedTextLayer.fontSize = self.selectedFont.pointSize; 73 | selectedTextLayer.foregroundColor = self.selectedTextColor.CGColor; 74 | selectedTextLayer.string = self.segment.selectedText; 75 | selectedTextLayer.contentsScale = [UIScreen mainScreen].scale; 76 | _selectedTextLayer = selectedTextLayer; 77 | [self addSublayer:selectedTextLayer]; 78 | } 79 | } 80 | return _selectedTextLayer; 81 | } 82 | 83 | - (CALayer *)imageLayer{ 84 | if (!_imageLayer) { 85 | if (self.segment.image) { 86 | CALayer *imageLayer = [CALayer layer]; 87 | imageLayer.frame = [self imageLayerFrameForImage:self.segment.image]; 88 | imageLayer.contents = (id)self.segment.image.CGImage; 89 | _imageLayer = imageLayer; 90 | [self addSublayer:imageLayer]; 91 | } 92 | } 93 | return _imageLayer; 94 | } 95 | 96 | - (CALayer *)selectedImageLayer{ 97 | if (!_selectedImageLayer) { 98 | if (self.segment.image) { 99 | CALayer *selectedImageLayer = [CALayer layer]; 100 | selectedImageLayer.frame = [self imageLayerFrameForImage:self.segment.selectedImage]; 101 | selectedImageLayer.contents = (id)self.segment.selectedImage.CGImage; 102 | _selectedImageLayer = selectedImageLayer; 103 | [self addSublayer:selectedImageLayer]; 104 | } 105 | } 106 | return _selectedImageLayer; 107 | } 108 | 109 | - (CALayer *)redPointLayer{ 110 | if (!_redPointLayer) { 111 | CALayer *redPointLayer = [CALayer layer]; 112 | redPointLayer.frame = CGRectMake(0, 0, 6, 6); 113 | redPointLayer.masksToBounds = YES; 114 | redPointLayer.cornerRadius = 3; 115 | redPointLayer.backgroundColor = [UIColor redColor].CGColor; 116 | redPointLayer.hidden = !self.showRedPoint; 117 | _redPointLayer = redPointLayer; 118 | [self addSublayer:redPointLayer]; 119 | self.redPointInsets = UIEdgeInsetsMake(12, 0, 0, 20); 120 | } 121 | return _redPointLayer; 122 | } 123 | 124 | - (void)setShowRedPoint:(BOOL)showRedPoint{ 125 | _showRedPoint = showRedPoint; 126 | self.redPointLayer.hidden = !showRedPoint; 127 | } 128 | 129 | - (void)setRedPointInsets:(UIEdgeInsets)redPointInsets{ 130 | _redPointInsets = redPointInsets; 131 | self.redPointLayer.position = CGPointMake(self.bounds.size.width - self.contentInsets.right - self.redPointInsets.right, self.contentInsets.top + self.redPointInsets.top); 132 | } 133 | 134 | - (void)setSegment:(VOSegment *)segment{ 135 | _segment = segment; 136 | if (!_segment.selectedText) { 137 | _segment.selectedText = _segment.text; 138 | } 139 | if (!_segment.selectedImage) { 140 | _segment.selectedImage = _segment.image; 141 | } 142 | } 143 | 144 | - (void)layoutSublayers{ 145 | [super layoutSublayers]; 146 | [self setSelected:_selected]; 147 | } 148 | 149 | - (void)setSelected:(BOOL)selected{ 150 | [self setSelected:selected animated:NO completion:nil]; 151 | } 152 | 153 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated completion: (void (^)())completion{ 154 | _selected = selected; 155 | if (animated) { 156 | [CATransaction begin]; 157 | [CATransaction setAnimationDuration: kContentAnimationDuration]; 158 | [CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 159 | if (completion) { 160 | [CATransaction setCompletionBlock:completion]; 161 | } 162 | } 163 | 164 | if (selected) { 165 | self.backgroundColor = self.selectedbackgroundColor.CGColor; 166 | if(self.textLayer) self.textLayer.opacity = 0.0; 167 | if(self.selectedTextLayer) self.selectedTextLayer.opacity = 1.0; 168 | if(self.imageLayer) self.imageLayer.opacity = 0.0; 169 | if(self.selectedImageLayer) self.selectedImageLayer.opacity = 1.0; 170 | } 171 | else{ 172 | self.backgroundColor = self.normalBackgroundColor.CGColor; 173 | if(self.textLayer) self.textLayer.opacity = 1.0; 174 | if(self.selectedTextLayer) self.selectedTextLayer.opacity = 0.0; 175 | if(self.imageLayer) self.imageLayer.opacity = 1.0; 176 | if(self.selectedImageLayer) self.selectedImageLayer.opacity = 0.0; 177 | } 178 | if (animated) { 179 | [CATransaction commit]; 180 | } 181 | else{ 182 | if (completion) { 183 | completion(); 184 | } 185 | } 186 | } 187 | 188 | // 计算textLayer显示时的frame 189 | - (CGRect)textLayerFrameForSegment: (id)text andFont: (UIFont *)font{ 190 | CGSize textSize = [self getTextSize:text andFont: font]; 191 | CGRect contentRect = UIEdgeInsetsInsetRect(self.bounds, self.contentInsets); 192 | CGSize size = contentRect.size; 193 | CGRect frame = CGRectZero; 194 | frame.size = textSize; 195 | switch (self.contentStyle) { 196 | case VOContentStyleTextAlone: 197 | frame.origin = CGPointMake((size.width - textSize.width) / 2, (size.height - textSize.height) / 2); 198 | break; 199 | case VOContentStyleImageLeft: 200 | frame.origin = CGPointMake(size.height + kTextImagePadding, (size.height - textSize.height) / 2); 201 | break; 202 | case VOContentStyleImageRight: 203 | frame.origin = CGPointMake(size.width - size.height - textSize.width - kTextImagePadding, (size.height - textSize.height) / 2); 204 | break; 205 | case VOContentStyleImageTop: 206 | frame.origin = CGPointMake((size.width - textSize.width) / 2, size.height * 0.618 + kTextImagePadding); 207 | break; 208 | case VOContentStyleImageBottom: 209 | frame.origin = CGPointMake((size.width - textSize.width) / 2, size.height * 0.382 - textSize.height - kTextImagePadding); 210 | break; 211 | default: 212 | break; 213 | } 214 | frame = CGRectOffset(frame, self.contentInsets.left, self.contentInsets.top); 215 | return frame; 216 | } 217 | 218 | //计算imageLayer显示的frame 219 | - (CGRect)imageLayerFrameForImage: (UIImage *)image{ 220 | CGSize imageSize = [self getImageSize:image]; 221 | CGRect contentRect = UIEdgeInsetsInsetRect(self.bounds, self.contentInsets); 222 | CGSize size = contentRect.size; 223 | CGRect frame = CGRectZero; 224 | frame.size = imageSize; 225 | switch (self.contentStyle) { 226 | case VOContentStyleImageAlone: 227 | frame.origin = CGPointMake((size.width - imageSize.width) / 2, (size.height - imageSize.height) / 2); 228 | break; 229 | case VOContentStyleImageLeft: 230 | frame.origin = CGPointMake(size.height - imageSize.width - kTextImagePadding, (size.height - imageSize.height) / 2); 231 | break; 232 | case VOContentStyleImageRight: 233 | frame.origin = CGPointMake(size.height + kTextImagePadding, (size.height - imageSize.height) / 2); 234 | break; 235 | case VOContentStyleImageTop: 236 | frame.origin = CGPointMake((size.width - imageSize.width) / 2, size.height * 0.618 - imageSize.height - kTextImagePadding); 237 | break; 238 | case VOContentStyleImageBottom: 239 | frame.origin = CGPointMake((size.width - imageSize.width) / 2, size.height * 0.382 + kTextImagePadding); 240 | break; 241 | default: 242 | break; 243 | } 244 | frame = CGRectOffset(frame, self.contentInsets.left, self.contentInsets.top); 245 | return frame; 246 | } 247 | 248 | - (CGSize)getImageSize:(UIImage *)image{ 249 | CGSize maxImageSize = CGSizeZero; 250 | CGSize size = self.bounds.size; 251 | CGSize imageSize = image.size; 252 | 253 | switch (self.contentStyle) { 254 | case VOContentStyleImageLeft: 255 | case VOContentStyleImageRight: 256 | maxImageSize = CGSizeMake(size.height, size.height); 257 | break; 258 | case VOContentStyleImageTop: 259 | case VOContentStyleImageBottom: 260 | maxImageSize = CGSizeMake(size.width, size.height * 0.618); 261 | break; 262 | 263 | case VOContentStyleImageAlone: 264 | maxImageSize = self.bounds.size; 265 | break; 266 | 267 | default: 268 | return CGSizeZero; 269 | } 270 | CGFloat imageRatio = imageSize.width / imageSize.height; 271 | CGFloat maxSizeRatio = maxImageSize.width / maxImageSize.height; 272 | CGSize showSize = CGSizeZero; 273 | if(imageRatio > maxSizeRatio){ 274 | showSize.width = MIN(maxImageSize.width, imageSize.width); 275 | showSize.height = imageSize.height / (imageSize.width / showSize.width); 276 | } 277 | else{ 278 | showSize.height = MIN(maxImageSize.height, imageSize.height); 279 | showSize.width = imageSize.width / (imageSize.height / showSize.height); 280 | } 281 | 282 | return showSize; 283 | } 284 | 285 | - (CGSize)getTextSize: (id)text andFont: (UIFont *)font{ 286 | if (!text) { 287 | return CGSizeZero; 288 | } 289 | NSString *str = nil; 290 | NSDictionary *attributes = nil; 291 | if ([text isKindOfClass: [NSString class]]) { 292 | str = text; 293 | attributes = @{NSFontAttributeName: font}; 294 | } 295 | else if([text isKindOfClass:[NSAttributedString class]]) 296 | { 297 | NSRange range; 298 | NSAttributedString *attrStr = (NSAttributedString *)text; 299 | str = attrStr.string; 300 | attributes = [attrStr attributesAtIndex:0 effectiveRange:&range]; 301 | } 302 | if ([text respondsToSelector:@selector(sizeWithAttributes:)]) { 303 | return [str sizeWithAttributes: attributes]; 304 | } 305 | else { 306 | #pragma clang diagnostic push 307 | #pragma GCC diagnostic ignored "-Wdeprecated" 308 | return [str sizeWithFont:font]; 309 | #pragma clang diagnostic pop 310 | } 311 | } 312 | 313 | 314 | @end 315 | -------------------------------------------------------------------------------- /VOSegmentedControlDemo/VOSegmentedControl/VOIndicatorAnimation.h: -------------------------------------------------------------------------------- 1 | // 2 | // VOLayerAnimation.h 3 | // VOSegmentedControlDemo 4 | // 5 | // Created by Valo Lee on 14-11-30. 6 | // Copyright (c) 2014年 valo. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | /** 13 | * 指示器专用的动画效果 14 | * @desc 指示器相关动画不会更改指示器Layer的frame,只更改position, 弹簧效果会对Layer的bounds进行操作. 15 | */ 16 | @interface VOIndicatorAnimation : NSObject 17 | /** 18 | * 弹簧效果 19 | * 20 | * @param indicator 要进行动画的Layer 21 | * @param fromPos 开始移动的位置 22 | * @param toPos 移动结束的位置 23 | * @param duration 动画执行的时间 24 | */ 25 | + (void)bounceMoveIndicator: (CALayer *)indicator fromPostion: (CGPoint)fromPos toPosition: (CGPoint)toPos duration: (CGFloat)duration; 26 | 27 | /** 28 | * 平滑效果 29 | * 30 | * @param indicator 要进行动画的Layer 31 | * @param fromPos 开始移动的位置 32 | * @param toPos 移动结束的位置 33 | * @param duration 动画执行的时间 34 | */ 35 | + (void)smoothMoveIndicator: (CALayer *)indicator fromPostion: (CGPoint)fromPos toPosition: (CGPoint)toPos duration: (CGFloat)duration; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /VOSegmentedControlDemo/VOSegmentedControl/VOIndicatorAnimation.m: -------------------------------------------------------------------------------- 1 | // 2 | // VOLayerAnimation.m 3 | // VOSegmentedControlDemo 4 | // 5 | // Created by Valo Lee on 14-11-30. 6 | // Copyright (c) 2014年 valo. All rights reserved. 7 | // 8 | 9 | #import "VOIndicatorAnimation.h" 10 | 11 | @implementation VOIndicatorAnimation 12 | 13 | + (void)bounceMoveIndicator: (CALayer *)indicator fromPostion: (CGPoint)fromPos toPosition: (CGPoint)toPos duration: (CGFloat)duration{ 14 | CGSize size = indicator.bounds.size; 15 | CGFloat bounceDuration, moveDuration; 16 | if (CGPointEqualToPoint(fromPos, toPos)) { 17 | moveDuration = 0.0; 18 | bounceDuration = duration; 19 | } 20 | else{ 21 | moveDuration = duration * 0.25; 22 | bounceDuration = duration * 0.75; 23 | } 24 | CABasicAnimation *moveAnim = [CABasicAnimation animation]; 25 | moveAnim.keyPath = @"position"; 26 | moveAnim.fromValue = [NSValue valueWithCGPoint:fromPos]; 27 | moveAnim.toValue = [NSValue valueWithCGPoint:toPos]; 28 | moveAnim.duration = moveDuration; 29 | moveAnim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; 30 | moveAnim.removedOnCompletion = NO; 31 | moveAnim.fillMode = kCAFillModeForwards; 32 | [indicator addAnimation:moveAnim forKey:nil]; 33 | 34 | NSMutableArray *values = [NSMutableArray array]; 35 | CGFloat maxWidth = size.width + ABS(toPos.x - fromPos.x); 36 | CGFloat firstDamp = 1.0 - size.width / maxWidth; 37 | CGFloat damp = 0.75; 38 | CGFloat drift = size.width * firstDamp * -1.0; 39 | for (NSInteger i = 0; i < bounceDuration / 0.15; i ++) { 40 | [values addObject:[NSValue valueWithCGRect:CGRectMake(0, 0, size.width + drift, size.height)]]; 41 | drift = drift * -damp; 42 | } 43 | // 最后状态 44 | [values addObject:[NSValue valueWithCGRect:CGRectMake(0, 0, size.width, size.height)]]; 45 | CAKeyframeAnimation *keyanim = [CAKeyframeAnimation animation]; 46 | keyanim.keyPath = @"bounds"; 47 | keyanim.values = values; 48 | keyanim.removedOnCompletion = NO; 49 | keyanim.fillMode = kCAFillModeForwards; 50 | keyanim.duration = bounceDuration; 51 | keyanim.beginTime = [indicator convertTime:CACurrentMediaTime() fromLayer:nil] + duration * 0.25; 52 | keyanim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; 53 | 54 | [indicator addAnimation:keyanim forKey:nil]; 55 | } 56 | 57 | + (void)smoothMoveIndicator: (CALayer *)indicator fromPostion: (CGPoint)fromPos toPosition: (CGPoint)toPos duration: (CGFloat)duration{ 58 | if (CGPointEqualToPoint(fromPos, toPos)) { 59 | return; 60 | } 61 | CABasicAnimation *moveAnim = [CABasicAnimation animation]; 62 | moveAnim.keyPath = @"position"; 63 | moveAnim.fromValue = [NSValue valueWithCGPoint:fromPos]; 64 | moveAnim.toValue = [NSValue valueWithCGPoint:toPos]; 65 | moveAnim.duration = duration; 66 | moveAnim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 67 | moveAnim.removedOnCompletion = NO; 68 | moveAnim.fillMode = kCAFillModeForwards; 69 | [indicator addAnimation:moveAnim forKey:nil]; 70 | } 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /VOSegmentedControlDemo/VOSegmentedControl/VOSegment.h: -------------------------------------------------------------------------------- 1 | // 2 | // VOSegment.h 3 | // VOSegmentedControlDemo 4 | // 5 | // Created by Valo Lee on 14-11-27. 6 | // Copyright (c) 2014年 valo. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | UIKIT_EXTERN NSString const *VOSegmentText; 12 | UIKIT_EXTERN NSString const *VOSegmentSelectedText; 13 | UIKIT_EXTERN NSString const *VOSegmentImage; 14 | UIKIT_EXTERN NSString const *VOSegmentSelectedImage; 15 | UIKIT_EXTERN NSString const *VOSegmentBackgroundImage; 16 | UIKIT_EXTERN NSString const *VOSegmentSelectedBackgroundImage; 17 | 18 | /** 19 | * 描述Segment的数据模型 20 | */ 21 | @interface VOSegment : NSObject 22 | @property (nonatomic, strong) id text; // 文字,NSString或NSAttributedString, 与图像二者必选其一 23 | @property (nonatomic, strong) id selectedText; // 选中状态的文字, 默认与非选中状态一样 24 | @property (nonatomic, strong) UIImage *image; // 图像, 与文字二者必选其一 25 | @property (nonatomic, strong) UIImage *selectedImage; // 选中状态的图像, 默认与非选中状态一样 26 | @property (nonatomic, strong) UIImage *backgroundImage; // 背景图像 27 | @property (nonatomic, strong) UIImage *selectedBackgroundImage; // 选中状态的背景图像 28 | @property (nonatomic, assign) BOOL enabled; // 启用/禁用 29 | 30 | /** 31 | * 从NSDictionary生成VOSegment 32 | * 33 | * @param segmentdic NSDictionary,包含segment的各种参数 34 | * 35 | * @return VOSegment对象 36 | */ 37 | + (instancetype)segmentFromDictionary:(NSDictionary *)segmentdic; 38 | + (BOOL)isValidSegment: (VOSegment *)segment; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /VOSegmentedControlDemo/VOSegmentedControl/VOSegment.m: -------------------------------------------------------------------------------- 1 | // 2 | // VOSegment.m 3 | // VOSegmentedControlDemo 4 | // 5 | // Created by Valo Lee on 14-11-27. 6 | // Copyright (c) 2014年 valo. All rights reserved. 7 | // 8 | 9 | #import "VOSegment.h" 10 | 11 | NSString const *VOSegmentText = @"text"; 12 | NSString const *VOSegmentSelectedText = @"selectedText"; 13 | NSString const *VOSegmentImage = @"image"; 14 | NSString const *VOSegmentSelectedImage = @"selectedImage"; 15 | NSString const *VOSegmentBackgroundImage = @"backgroundImage"; 16 | NSString const *VOSegmentSelectedBackgroundImage = @"selectedBackgroundImage"; 17 | 18 | 19 | @implementation VOSegment 20 | 21 | + (UIImage *)imageFormUIImageOrNSString: (id)image{ 22 | if ([image isKindOfClass:[UIImage class]]) { 23 | return image; 24 | } 25 | else if([image isKindOfClass:[NSString class]]){ 26 | return [UIImage imageNamed:image]; 27 | } 28 | else{ 29 | return nil; 30 | } 31 | } 32 | 33 | + (instancetype)segmentFromDictionary:(NSDictionary *)segmentdic{ 34 | VOSegment *segment = [[VOSegment alloc] init]; 35 | segment.text = segmentdic[VOSegmentText]; 36 | segment.selectedText = segmentdic[VOSegmentSelectedText]; 37 | segment.image = [VOSegment imageFormUIImageOrNSString:segmentdic[VOSegmentImage]]; 38 | segment.selectedImage = [VOSegment imageFormUIImageOrNSString:segmentdic[VOSegmentSelectedImage]]; 39 | segment.backgroundImage = [VOSegment imageFormUIImageOrNSString:segmentdic[VOSegmentBackgroundImage]]; 40 | segment.selectedBackgroundImage = [VOSegment imageFormUIImageOrNSString:segmentdic[VOSegmentSelectedBackgroundImage]]; 41 | 42 | if (segmentdic[@"enabled"]) { 43 | segment.enabled = [segmentdic[@"enabled"] boolValue]; 44 | } 45 | else{ 46 | segment.enabled = YES; //默认启用 47 | } 48 | return segment; 49 | } 50 | 51 | + (BOOL)isValidSegment: (VOSegment *)segment{ 52 | return (segment.text || segment.image); 53 | } 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /VOSegmentedControlDemo/VOSegmentedControl/VOSegmentedControl.h: -------------------------------------------------------------------------------- 1 | // 2 | // VOSegmentedControl.h 3 | // VOSegmentedControlDemo 4 | // 5 | // Created by Valo Lee on 14-11-19. 6 | // Copyright (c) 2014年 valo. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "VOContentLayer.h" 11 | 12 | #pragma mark - 防止[self performSelector:sel]警告 13 | #define SuppressPerformSelectorLeakWarning(Stuff) \ 14 | do { \ 15 | _Pragma("clang diagnostic push") \ 16 | _Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \ 17 | Stuff; \ 18 | _Pragma("clang diagnostic pop") \ 19 | } while (0) 20 | 21 | typedef NS_ENUM(NSUInteger, VOSegCtrlIndicatorStyle) { 22 | VOSegCtrlIndicatorStyleBottomLine, // 底部横线 23 | VOSegCtrlIndicatorStyleTopLine, // 顶部横线 24 | VOSegCtrlIndicatorStyleBox, // 方框,泡泡 25 | }; 26 | 27 | typedef NS_ENUM(NSUInteger, VOSegCtrlAnimationType) { 28 | VOSegCtrlAnimationTypeSmooth, // 平滑 29 | VOSegCtrlAnimationTypeBounce, // 跳动 30 | }; 31 | 32 | enum { 33 | VOSegmentedControlNoSegment = -1 // 未选择Segment 34 | }; 35 | 36 | #define kDefaultDuration 0.3 37 | 38 | 39 | @interface VOSegmentedControl : UIControl 40 | 41 | #pragma mark 样式 42 | @property (nonatomic, assign) VOContentStyle contentStyle; 43 | @property (nonatomic, assign) VOSegCtrlIndicatorStyle indicatorStyle; 44 | @property (nonatomic, assign) VOSegCtrlAnimationType animationType; 45 | @property (nonatomic, assign) BOOL allowNoSelection; 46 | @property (nonatomic, assign) BOOL scrollBounce; 47 | 48 | #pragma mark 色彩 49 | @property (nonatomic, strong ) UIColor *textColor; 50 | @property (nonatomic, strong ) UIColor *selectedTextColor; 51 | @property (nonatomic, strong ) UIColor *selectedBackgroundColor; 52 | 53 | #pragma mark Indicator属性 54 | @property (nonatomic, assign ) CGFloat indicatorThickness; 55 | @property (nonatomic, assign ) CGFloat indicatorCornerRadius; 56 | @property (nonatomic, strong ) UIColor *indicatorColor; 57 | @property (nonatomic, strong ) UIColor *selectedIndicatorColor; 58 | 59 | #pragma mark 分段 60 | @property (nonatomic,readonly) NSUInteger numberOfSegments; 61 | @property (nonatomic, assign ) NSInteger selectedSegmentIndex; 62 | @property (nonatomic, strong ) UIFont *textFont; 63 | @property (nonatomic, strong ) UIFont *selectedTextFont; 64 | 65 | #pragma mark 内容 66 | @property (nonatomic, strong ) NSArray *segments; 67 | 68 | #pragma mark indexchange 69 | @property (nonatomic, copy ) void (^indexChangeBlock)(NSInteger index); 70 | 71 | /** 72 | * 使用NSDictionary类型的Item数组初始化控件 73 | * 74 | * @param segments VOSegment或者NSDictionary 75 | * @return VOSegmentedControl 76 | */ 77 | - (instancetype)initWithSegments:(NSArray *)segments; 78 | 79 | /** 80 | * 插入一个segment 81 | * 82 | * @param segment VOSegment或NSDictionary 83 | * @param index 插入的位置 84 | * @param animated 是否有动画效果 85 | */ 86 | - (void)insertSegment:(id)segment atIndex:(NSUInteger)index animated:(BOOL)animated; 87 | 88 | /** 89 | * 删除一个segment 90 | * 91 | * @param index 要删除的segment的位置 92 | * @param animated 是否有动画效果 93 | */ 94 | - (void)removeSegmentAtIndex:(NSUInteger)index animated:(BOOL)animated; 95 | 96 | /** 97 | * 删除所有segment 98 | */ 99 | - (void)removeAllSegments; 100 | 101 | /** 102 | * 设置指定位置的segment 103 | * 104 | * @param segment VOSegment或NSDictionary 105 | * @param index 设置的位置 106 | */ 107 | - (void)setSegment:(id)segment atIndex:(NSUInteger)index; 108 | 109 | /** 110 | * 获取指定位置的segment内容 111 | * 112 | * @param index segment的位置 113 | * 114 | * @return segment,字典类型, image和selectedimage为UIImage或nil 115 | */ 116 | - (VOSegment *)segmentAtIndex: (NSUInteger)index; 117 | 118 | /** 119 | * 启用/禁用某个segment 120 | * 121 | * @param enabled YES-启用, NO-禁用 122 | * @param index segment的位置 123 | */ 124 | - (void)setEnabled:(BOOL)enabled forSegmentAtIndex:(NSUInteger)index; 125 | 126 | /** 127 | * 获取segment的启用/禁用状态 128 | * 129 | * @param segment segment的位置 130 | * 131 | * @return YES-启用,NO-禁用 132 | */ 133 | - (BOOL)isEnabledForSegmentAtIndex:(NSUInteger)index; 134 | 135 | #pragma mark - 小红点 136 | /** 137 | * 设置小红点的位置(左上角为基准,inset的top和right有效) 138 | * 139 | * @param inset 位置 140 | * @param index 所在分段 141 | */ 142 | - (void)setInset:(UIEdgeInsets)inset forSegmentRedPointAtIndex:(NSUInteger)index; 143 | 144 | /** 145 | * 设置小红点是否显示 146 | * 147 | * @param show 是否显示 148 | * @param index 所在的分段 149 | */ 150 | - (void)setShow:(BOOL)show forSegmentRedPointAtIndex:(NSUInteger)index; 151 | 152 | /** 153 | * 小红点的显示状态 154 | * 155 | * @param index 所在的分段 156 | * 157 | * @return 是否显示 158 | */ 159 | - (BOOL)isSegmentRedPointShowAtIndex:(NSUInteger)index; 160 | 161 | @end -------------------------------------------------------------------------------- /VOSegmentedControlDemo/VOSegmentedControl/VOSegmentedControl.m: -------------------------------------------------------------------------------- 1 | // 2 | // VOSegmentedControl.m 3 | // VOSegmentedControlDemo 4 | // 5 | // Created by Valo Lee on 14-11-19. 6 | // Copyright (c) 2014年 valo. All rights reserved. 7 | // 8 | 9 | #import "VOSegmentedControl.h" 10 | #import "VOIndicatorAnimation.h" 11 | 12 | #define kTextPadding 8 13 | 14 | #pragma mark - VOSegmentedControl 15 | @interface VOSegmentedControl () 16 | @property (nonatomic, strong) NSMutableArray *segmentArray; 17 | @property (nonatomic, strong) NSMutableArray *contentLayerArray; 18 | @property (nonatomic, strong) NSMutableDictionary *showRedPointDic; 19 | @property (nonatomic, strong) NSMutableDictionary *redPointInsetsDic; 20 | 21 | @property (nonatomic, strong) CAScrollLayer *scrollLayer; 22 | @property (nonatomic, strong) CALayer *indicatorLayer; 23 | 24 | @property (nonatomic, assign) CGSize segSize; 25 | 26 | @property (nonatomic, assign) CGPoint lastPoint; 27 | @property (nonatomic, assign) CGPoint startPoint; 28 | @property (nonatomic, assign) BOOL isClick; 29 | 30 | @property (nonatomic, assign) CGPoint indicatorPos; 31 | @end 32 | 33 | @implementation VOSegmentedControl 34 | 35 | - (instancetype)initWithFrame:(CGRect)frame{ 36 | if (self = [super initWithFrame:frame]) { 37 | [self commonInit]; 38 | } 39 | return self; 40 | } 41 | 42 | - (instancetype)initWithCoder:(NSCoder *)aDecoder{ 43 | if (self = [super initWithCoder:aDecoder]) { 44 | [self commonInit]; 45 | } 46 | return self; 47 | } 48 | 49 | - (instancetype)initWithSegments:(NSArray *)segments{ 50 | if (self = [super initWithFrame:CGRectZero]) { 51 | [self commonInit]; 52 | // 1. 初始化存放segments各种参数的数组 53 | [self setSegments:segments]; 54 | } 55 | return self; 56 | } 57 | 58 | - (void)commonInit{ 59 | // array 60 | self.segmentArray = [NSMutableArray array]; 61 | self.contentLayerArray = [NSMutableArray array]; 62 | self.showRedPointDic = [NSMutableDictionary dictionary]; 63 | self.redPointInsetsDic = [NSMutableDictionary dictionary]; 64 | 65 | // ScrollView 66 | 67 | // 样式 68 | self.contentStyle = VOContentStyleTextAlone; 69 | self.indicatorStyle = VOSegCtrlIndicatorStyleBox; 70 | self.animationType = VOSegCtrlAnimationTypeBounce; 71 | self.allowNoSelection = YES; 72 | self.scrollBounce = YES; 73 | 74 | // 色彩 75 | self.textColor = [UIColor blackColor]; 76 | self.selectedTextColor = [UIColor redColor]; 77 | self.backgroundColor = [UIColor whiteColor]; 78 | self.selectedBackgroundColor = [UIColor whiteColor]; 79 | 80 | // indicator属性 81 | self.indicatorThickness = 0; 82 | self.indicatorCornerRadius = 0; 83 | self.indicatorColor = [UIColor clearColor]; 84 | self.selectedIndicatorColor = [UIColor redColor]; 85 | 86 | // 分段 87 | self.textFont = [UIFont systemFontOfSize:14]; 88 | self.selectedTextFont = [UIFont systemFontOfSize:14]; 89 | 90 | // Layer 91 | self.scrollLayer = [CAScrollLayer layer]; 92 | 93 | // test 94 | _selectedSegmentIndex = 0; 95 | } 96 | 97 | - (CALayer *)indicatorLayer{ 98 | if (!_indicatorLayer) { 99 | CALayer *indicatorLayer = [CALayer layer]; 100 | switch (self.indicatorStyle) { 101 | case VOSegCtrlIndicatorStyleTopLine: 102 | case VOSegCtrlIndicatorStyleBottomLine: 103 | indicatorLayer.cornerRadius = self.indicatorCornerRadius; 104 | indicatorLayer.backgroundColor = self.selectedIndicatorColor.CGColor; 105 | break; 106 | 107 | case VOSegCtrlIndicatorStyleBox: 108 | indicatorLayer.backgroundColor = [UIColor clearColor].CGColor; 109 | indicatorLayer.borderWidth = self.indicatorThickness; 110 | indicatorLayer.cornerRadius = self.indicatorCornerRadius; 111 | indicatorLayer.borderColor = self.selectedIndicatorColor.CGColor; 112 | break; 113 | 114 | default: 115 | break; 116 | } 117 | _indicatorLayer = indicatorLayer; 118 | } 119 | return _indicatorLayer; 120 | } 121 | 122 | - (void)setIndicatorStyle:(VOSegCtrlIndicatorStyle)indicatorStyle{ 123 | _indicatorStyle = indicatorStyle; 124 | _indicatorLayer = nil; 125 | [self setNeedsDisplay]; 126 | } 127 | 128 | - (NSUInteger)numberOfSegments{ 129 | return self.segmentArray.count; 130 | } 131 | 132 | - (void)setSegments:(NSArray *)segments{ 133 | [self.segmentArray removeAllObjects]; 134 | for (id segment in segments) { 135 | if ([segment isKindOfClass:[VOSegment class]]) { 136 | if ([VOSegment isValidSegment:segment]) { 137 | [self.segmentArray addObject:segment]; 138 | } 139 | } 140 | if ([segment isKindOfClass:[NSDictionary class]]) { 141 | VOSegment *seg = [VOSegment segmentFromDictionary:segment]; 142 | if ([VOSegment isValidSegment:seg]) { 143 | [self.segmentArray addObject:[VOSegment segmentFromDictionary:segment]]; 144 | } 145 | } 146 | } 147 | [self setNeedsDisplay]; 148 | } 149 | 150 | - (NSArray *)segments{ 151 | return _segmentArray; 152 | } 153 | 154 | - (void)insertSegment:(id)segment atIndex:(NSUInteger)index animated:(BOOL)animated{ 155 | // 1. 先讲segment插入数组 156 | VOSegment *willInsertSegment = nil; 157 | if ([segment isKindOfClass:[VOSegment class]]) { 158 | willInsertSegment = segment; 159 | } 160 | if ([segment isKindOfClass:[NSDictionary class]]) { 161 | willInsertSegment = [VOSegment segmentFromDictionary:segment]; 162 | } 163 | if (willInsertSegment) { 164 | if (![VOSegment isValidSegment:willInsertSegment] || index >= self.segmentArray.count) { 165 | return; 166 | } 167 | [self.segmentArray insertObject:willInsertSegment atIndex:index]; 168 | [self setNeedsDisplay]; 169 | } 170 | } 171 | 172 | - (void)removeSegmentAtIndex:(NSUInteger)index animated:(BOOL)animated{ 173 | //TODO 先将segment从屏幕显示移除 174 | 175 | // 2. 先讲segment从数组删除 176 | if (index >= self.segmentArray.count) { 177 | return; 178 | } 179 | [self.segmentArray removeObjectAtIndex:index]; 180 | [self setNeedsDisplay]; 181 | } 182 | 183 | - (void)removeAllSegments{ 184 | // 1. 将控件从屏幕移除 185 | [self removeFromSuperview]; 186 | 187 | // 2. 删除所有segment 188 | [self.segmentArray removeAllObjects]; 189 | 190 | [self setNeedsDisplay]; 191 | } 192 | 193 | - (void)setSegment:(id)segment atIndex:(NSUInteger)index{ 194 | // 1. 替换数组中的元素 195 | VOSegment *willReplaceSegment = nil; 196 | if ([segment isKindOfClass:[VOSegment class]]) { 197 | willReplaceSegment = segment; 198 | } 199 | if ([segment isKindOfClass:[NSDictionary class]]) { 200 | willReplaceSegment = [VOSegment segmentFromDictionary:segment]; 201 | } 202 | if (willReplaceSegment) { 203 | if (![VOSegment isValidSegment:willReplaceSegment] || index >= self.segmentArray.count) { 204 | return; 205 | } 206 | [self.segmentArray replaceObjectAtIndex:index withObject:willReplaceSegment]; 207 | 208 | [self setNeedsDisplay]; 209 | } 210 | } 211 | 212 | - (VOSegment *)segmentAtIndex:(NSUInteger)index{ 213 | if (index >= self.segmentArray.count) { 214 | return nil; 215 | } 216 | return self.segmentArray[index]; 217 | } 218 | 219 | //TODO 220 | - (void)setEnabled:(BOOL)enabled forSegmentAtIndex:(NSUInteger)index{ 221 | // 设置参数 222 | if (index >= self.segmentArray.count) { 223 | return; 224 | } 225 | VOSegment *segment = self.segmentArray[index]; 226 | segment.enabled = enabled; 227 | } 228 | 229 | - (BOOL)isEnabledForSegmentAtIndex:(NSUInteger)index{ 230 | if (index >= self.segmentArray.count) { 231 | return NO; 232 | } 233 | VOSegment *segment = self.segmentArray[index]; 234 | return segment.enabled; 235 | } 236 | 237 | - (void)setFrame:(CGRect)frame{ 238 | [super setFrame:frame]; 239 | [self setNeedsDisplay]; 240 | } 241 | 242 | - (void)setBounds:(CGRect)bounds{ 243 | [super setBounds:bounds]; 244 | [self setNeedsDisplay]; 245 | } 246 | 247 | - (void)willMoveToSuperview:(UIView *)newSuperview{ 248 | [super willMoveToSuperview:newSuperview]; 249 | [self setNeedsDisplay]; 250 | } 251 | 252 | - (void)drawRect:(CGRect)rect { 253 | [super drawRect:rect]; 254 | if (self.segments.count > 0) { 255 | self.scrollLayer.frame = rect; 256 | self.scrollLayer.backgroundColor = [UIColor clearColor].CGColor; 257 | 258 | // 1. 填充背景 259 | [self.backgroundColor setFill]; 260 | UIRectFill(self.bounds); 261 | 262 | // 2. 移除所有sublayers 263 | self.scrollLayer.sublayers = nil; 264 | self.layer.sublayers = nil; 265 | 266 | // 3. 添加scrollLayer 267 | [self.layer addSublayer:self.scrollLayer]; 268 | 269 | // 4. 计算segmentSize, contentSize,contentInsets, textLayer和imageLayer在当前segment中的Frame; 270 | CGSize segSize, contentSize; 271 | UIEdgeInsets contentInsets; 272 | [self generateSegmentSize:&segSize andContentSize:&contentSize andContentInsets:&contentInsets]; 273 | self.segSize = segSize; 274 | 275 | // 5. 添加contentLayers 276 | [self.contentLayerArray removeAllObjects]; 277 | for (NSUInteger i = 0; i < self.segmentArray.count; i ++) { 278 | VOSegment *segment =self.segmentArray[i]; 279 | VOContentLayer *contentLayer = [VOContentLayer contentLayerWithFrame:CGRectMake(segSize.width * i, 0, segSize.width, segSize.height) 280 | contentInsets:contentInsets 281 | segment:segment 282 | contentStyle:self.contentStyle]; 283 | contentLayer.textColor = self.textColor; 284 | contentLayer.selectedTextColor = self.selectedTextColor; 285 | contentLayer.normalBackgroundColor = self.backgroundColor; 286 | contentLayer.selectedbackgroundColor = self.selectedBackgroundColor; 287 | contentLayer.font = self.textFont; 288 | contentLayer.selectedFont = self.selectedTextFont; 289 | if (self.indicatorStyle == VOSegCtrlIndicatorStyleBox) { 290 | contentLayer.cornerRadius = self.indicatorCornerRadius; 291 | } 292 | [self.contentLayerArray addObject:contentLayer]; 293 | } 294 | 295 | [self.contentLayerArray enumerateObjectsUsingBlock:^(VOContentLayer *contentLayer, NSUInteger idx, BOOL *stop) { 296 | [self.scrollLayer addSublayer:contentLayer]; 297 | // 6.设置选中状态 298 | if (idx == self.selectedSegmentIndex) { 299 | [contentLayer setSelected:YES]; 300 | } 301 | if (self.redPointInsetsDic[@(idx).stringValue]) { 302 | contentLayer.redPointInsets = [self.redPointInsetsDic[@(idx).stringValue] UIEdgeInsetsValue]; 303 | } 304 | contentLayer.showRedPoint = [self.showRedPointDic[@(idx).stringValue] boolValue]; 305 | }]; 306 | 307 | self.indicatorLayer.frame = self.scrollLayer.frame; 308 | self.indicatorLayer.bounds = [self indicatorBounds]; 309 | self.indicatorLayer.position = CGPointMake(self.segSize.width * self.selectedSegmentIndex + self.segSize.width / 2, [self indicatorBoundsY]); 310 | self.indicatorPos = self.indicatorLayer.position; 311 | [self.scrollLayer addSublayer:self.indicatorLayer]; 312 | [self scrollToIndex:_selectedSegmentIndex]; 313 | } 314 | } 315 | 316 | - (CGFloat)indicatorBoundsY{ 317 | CGFloat y = 0.0; 318 | switch (self.indicatorStyle) { 319 | case VOSegCtrlIndicatorStyleTopLine: 320 | y = self.indicatorThickness / 2; 321 | break; 322 | 323 | case VOSegCtrlIndicatorStyleBottomLine: 324 | y = self.segSize.height - self.indicatorThickness / 2; 325 | break; 326 | 327 | case VOSegCtrlIndicatorStyleBox: 328 | y = self.segSize.height / 2; 329 | break; 330 | default: 331 | break; 332 | } 333 | return y; 334 | 335 | } 336 | - (CGRect)indicatorBounds{ 337 | CGRect bounds = CGRectZero; 338 | switch (self.indicatorStyle) { 339 | case VOSegCtrlIndicatorStyleTopLine: 340 | bounds = CGRectMake(0, 0, self.segSize.width, self.indicatorThickness); 341 | break; 342 | 343 | case VOSegCtrlIndicatorStyleBottomLine: 344 | bounds = CGRectMake(0, self.segSize.height - self.indicatorThickness, self.segSize.width, self.indicatorThickness); 345 | break; 346 | 347 | case VOSegCtrlIndicatorStyleBox: 348 | bounds = CGRectMake(0, 0, self.segSize.width, self.segSize.height); 349 | 350 | default: 351 | break; 352 | } 353 | return bounds; 354 | } 355 | 356 | - (CGSize)getTextSize: (id)text andFont: (UIFont *)font{ 357 | if (!text) { 358 | return CGSizeZero; 359 | } 360 | NSString *str = nil; 361 | NSDictionary *attributes = nil; 362 | if ([text isKindOfClass: [NSString class]]) { 363 | str = text; 364 | attributes = @{NSFontAttributeName: font}; 365 | } 366 | else if([text isKindOfClass:[NSAttributedString class]]) 367 | { 368 | NSAttributedString *attrStr = (NSAttributedString *)text; 369 | str = attrStr.string; 370 | NSRange range; 371 | attributes = [attrStr attributesAtIndex:0 effectiveRange:&range]; 372 | } 373 | if ([text respondsToSelector:@selector(sizeWithAttributes:)]) { 374 | return [str sizeWithAttributes: attributes]; 375 | } 376 | else { 377 | #pragma clang diagnostic push 378 | #pragma GCC diagnostic ignored "-Wdeprecated" 379 | return [str sizeWithFont:font]; 380 | #pragma clang diagnostic pop 381 | } 382 | } 383 | 384 | - (void)generateSegmentSize:(CGSize *)segSize 385 | andContentSize:(CGSize *)contentSize 386 | andContentInsets:(UIEdgeInsets *)contentInsets{ 387 | // 1. 初始化 388 | *segSize = CGSizeZero; 389 | *contentSize = CGSizeZero; 390 | *contentInsets = UIEdgeInsetsZero; 391 | // 2. 获取contentInsets 392 | switch (self.indicatorStyle) { 393 | case VOSegCtrlIndicatorStyleBottomLine: 394 | contentInsets->bottom = self.indicatorThickness; 395 | break; 396 | case VOSegCtrlIndicatorStyleTopLine: 397 | contentInsets->top = self.indicatorThickness; 398 | break; 399 | case VOSegCtrlIndicatorStyleBox: 400 | contentInsets->top = contentInsets->bottom = contentInsets->left = contentInsets->right 401 | = (self.indicatorCornerRadius * 0.4142 + self.indicatorThickness / 2) / 1.4142; 402 | break; 403 | default: 404 | break; 405 | } 406 | // 3. segment高度 407 | segSize->height = self.frame.size.height; 408 | contentSize->height = segSize->height - contentInsets->top - contentInsets->bottom; 409 | 410 | // 4. 获取文字和图片最大宽度 411 | CGFloat maxTextWidth = [self getMaxTextWidth]; 412 | CGFloat maxImageWidth = [self getMaxImageWidthWithContentHeight:contentSize->height]; 413 | // 5. content宽度, textLayerSize 414 | switch (self.contentStyle) { 415 | case VOContentStyleTextAlone: 416 | contentSize->width = maxTextWidth; 417 | break; 418 | case VOContentStyleImageAlone: 419 | contentSize->width = maxImageWidth - contentInsets->left - contentInsets->right; //仅用于计算segment高度 420 | break; 421 | case VOContentStyleImageLeft: 422 | contentSize->width = maxTextWidth + contentSize->height; 423 | break; 424 | case VOContentStyleImageRight: 425 | contentSize->width = maxTextWidth + contentSize->height; 426 | break; 427 | case VOContentStyleImageTop: 428 | contentSize->width = MAX(maxTextWidth, maxImageWidth); 429 | break; 430 | case VOContentStyleImageBottom: 431 | contentSize->width = MAX(maxTextWidth, maxImageWidth); 432 | break; 433 | default: 434 | break; 435 | } 436 | // 7.segment宽度 437 | segSize->width = contentSize->width + contentInsets->left + contentInsets->right; 438 | segSize->width = MAX(segSize->width, self.frame.size.width / self.segmentArray.count); 439 | } 440 | 441 | - (CGFloat)getMaxTextWidth{ 442 | CGFloat width = 0.0; 443 | for (VOSegment *segment in self.segmentArray) { 444 | CGFloat textWidth = [self getTextSize:segment.text andFont:self.textFont].width; 445 | CGFloat selectedTextWidth = [self getTextSize:((segment.selectedText)? segment.selectedText:segment.text) andFont:self.selectedTextFont].width; 446 | width = MAX(width, textWidth); 447 | width = MAX(width, selectedTextWidth); 448 | } 449 | return width + kTextPadding * 2; 450 | } 451 | 452 | - (CGFloat)getMaxImageWidthWithContentHeight: (CGFloat)contentHeight{ 453 | CGFloat width = 0.0; 454 | CGFloat calcHeight = 0.0; 455 | switch (self.contentStyle) { 456 | case VOContentStyleImageAlone: 457 | calcHeight = self.frame.size.height; 458 | break; 459 | case VOContentStyleImageLeft: // 图片在左或者右时,图片最大高度为contentHeight 460 | case VOContentStyleImageRight: 461 | calcHeight = contentHeight; 462 | break; 463 | case VOContentStyleImageTop: // 图片在顶部或底部时,图片最大高度为contentHeight的黄金分割 464 | case VOContentStyleImageBottom: 465 | calcHeight = contentHeight * 0.618; 466 | break; 467 | default: 468 | break; 469 | } 470 | for (VOSegment *segment in self.segmentArray) { 471 | if (segment.image) { 472 | width = MAX(width, segment.image.size.width * calcHeight / segment.image.size.height); 473 | } 474 | if (segment.selectedImage) { 475 | width = MAX(width, segment.selectedImage.size.width * calcHeight / segment.selectedImage.size.height); 476 | } 477 | } 478 | return width; 479 | } 480 | 481 | #pragma mark - Index change 482 | 483 | - (void)setSelectedSegmentIndex:(NSInteger)index { 484 | [self setSelectedSegmentIndex:index animated:NO notify:YES]; 485 | } 486 | 487 | - (void)setSelectedSegmentIndex:(NSInteger)index animated:(BOOL)animated { 488 | [self setSelectedSegmentIndex:index animated:animated notify:YES]; 489 | } 490 | 491 | - (void)setSelectedSegmentIndex:(NSInteger)index animated:(BOOL)animated notify:(BOOL)notify { 492 | if (!self.allowNoSelection && index < 0) { 493 | return; 494 | } 495 | if (index == VOSegmentedControlNoSegment) { 496 | [self.indicatorLayer removeFromSuperlayer]; 497 | } 498 | else{ 499 | [self scrollToIndex: index]; 500 | } 501 | NSInteger oldIndex = _selectedSegmentIndex; 502 | _selectedSegmentIndex = index; 503 | if (notify) { 504 | [self notifyForSegmentChangeToIndex:index]; 505 | } 506 | void(^moveIndicatorBlock)() = ^() { 507 | [self indicatorChangeFromIndex:oldIndex ToIndex:index animated:animated]; 508 | }; 509 | if (animated) { 510 | [CATransaction begin]; 511 | [CATransaction setAnimationDuration:kDefaultDuration]; 512 | [CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 513 | [CATransaction setCompletionBlock:moveIndicatorBlock]; 514 | } 515 | VOContentLayer *oldSelectedLayer = nil; 516 | VOContentLayer *willSelectedLayer = nil; 517 | if (oldIndex == VOSegmentedControlNoSegment) { 518 | [self.scrollLayer addSublayer:self.indicatorLayer]; 519 | } 520 | if (oldIndex != VOSegmentedControlNoSegment && self.contentLayerArray.count > oldIndex) { 521 | oldSelectedLayer = self.contentLayerArray[oldIndex]; 522 | [oldSelectedLayer setSelected:NO animated:animated completion:nil]; 523 | } 524 | if (index != VOSegmentedControlNoSegment && self.contentLayerArray.count > index) { 525 | willSelectedLayer = self.contentLayerArray[index]; 526 | [willSelectedLayer setSelected:YES animated:animated completion:moveIndicatorBlock]; 527 | } 528 | 529 | if (animated) { 530 | [CATransaction commit]; 531 | } 532 | } 533 | 534 | - (void)scrollToIndex: (NSInteger)index { 535 | if (index == VOSegmentedControlNoSegment) { 536 | return; 537 | } 538 | CGFloat contentWidth = self.segSize.width * self.segmentArray.count; 539 | if (contentWidth <= self.frame.size.width) { 540 | return; 541 | } 542 | CGPoint scrollToOffset = CGPointZero; 543 | CGFloat segmentCenterX = index * self.segSize.width + self.segSize.width / 2; 544 | CGFloat frameHalfWidth = self.frame.size.width / 2; 545 | if (segmentCenterX > frameHalfWidth && segmentCenterX < contentWidth - frameHalfWidth) { 546 | scrollToOffset.x = segmentCenterX - frameHalfWidth; 547 | } 548 | else if(segmentCenterX >= contentWidth - frameHalfWidth){ 549 | scrollToOffset.x = contentWidth - self.frame.size.width; 550 | } 551 | [self.scrollLayer scrollToPoint:scrollToOffset]; 552 | self.lastPoint = scrollToOffset; 553 | } 554 | 555 | - (void)indicatorChangeFromIndex: (NSInteger)fromIndex ToIndex: (NSInteger)toIndex animated: (BOOL)animated{ 556 | CGSize size = self.indicatorLayer.bounds.size; 557 | CGPoint fromPos = self.indicatorPos; 558 | CGPoint toPos = CGPointMake(size.width * toIndex + size.width / 2, [self indicatorBoundsY]); 559 | if (fromIndex == VOSegmentedControlNoSegment) { 560 | fromPos = toPos; 561 | } 562 | 563 | if (animated) { 564 | switch (self.animationType) { 565 | case VOSegCtrlAnimationTypeSmooth: 566 | [VOIndicatorAnimation smoothMoveIndicator:self.indicatorLayer fromPostion:fromPos toPosition:toPos duration:kDefaultDuration]; 567 | break; 568 | case VOSegCtrlAnimationTypeBounce: 569 | [VOIndicatorAnimation bounceMoveIndicator:self.indicatorLayer fromPostion:fromPos toPosition:toPos duration:kDefaultDuration]; 570 | break; 571 | 572 | default: 573 | [VOIndicatorAnimation smoothMoveIndicator:self.indicatorLayer fromPostion:fromPos toPosition:toPos duration:kDefaultDuration]; 574 | break; 575 | } 576 | } 577 | else{ 578 | [VOIndicatorAnimation smoothMoveIndicator:self.indicatorLayer fromPostion:fromPos toPosition:toPos duration:kDefaultDuration]; 579 | } 580 | self.indicatorPos = toPos; 581 | 582 | } 583 | 584 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 585 | UITouch *touch = [[event touchesForView:self] anyObject]; 586 | self.startPoint = [touch locationInView:self]; 587 | self.isClick = YES; 588 | } 589 | 590 | - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ 591 | UITouch *touch = [[event touchesForView:self] anyObject]; 592 | CGPoint point = [touch locationInView:self]; 593 | CGFloat moveX = ABS(point.x - self.startPoint.x); 594 | CGFloat moveY = ABS(point.y - self.startPoint.y); 595 | if (sqrt(moveX * moveX + moveY * moveY) > 10){ 596 | self.isClick = NO; 597 | } 598 | CGFloat leftX = 0; 599 | CGFloat rightX = self.segSize.width * self.segmentArray.count - self.bounds.size.width; 600 | CGFloat curX = self.lastPoint.x - point.x + self.startPoint.x; 601 | CGFloat lastX = MIN(MAX(leftX, curX), rightX); 602 | if (self.scrollBounce) { 603 | [self.scrollLayer scrollToPoint:CGPointMake(curX, 0)]; 604 | } 605 | else{ 606 | [self.scrollLayer scrollToPoint:CGPointMake(lastX, 0)]; 607 | } 608 | } 609 | 610 | - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ 611 | UITouch *touch = [[event touchesForView:self] anyObject]; 612 | CGPoint point = [touch locationInView:self]; 613 | CGFloat leftX = 0; 614 | CGFloat rightX = self.segSize.width * self.segmentArray.count - self.bounds.size.width; 615 | CGFloat curX = self.lastPoint.x - point.x + self.startPoint.x; 616 | CGFloat lastX = MIN(MAX(leftX, curX), rightX); 617 | if (curX < leftX || curX > rightX) { 618 | CGFloat edgeX = (curX < leftX)? 0: rightX; 619 | [self.scrollLayer scrollToPoint:CGPointMake(edgeX, 0)]; 620 | } 621 | self.lastPoint = CGPointMake(lastX, 0); 622 | if (self.isClick ) { 623 | if (CGRectContainsPoint(self.bounds, point)) { 624 | NSInteger index = (curX + point.x) / self.segSize.width; 625 | if (index != self.selectedSegmentIndex) { 626 | [self setSelectedSegmentIndex:index animated:YES notify:YES]; 627 | } 628 | else{ 629 | [self setSelectedSegmentIndex:VOSegmentedControlNoSegment animated:YES notify:YES]; 630 | } 631 | } 632 | } 633 | } 634 | 635 | - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{ 636 | [self touchesEnded:touches withEvent:event]; 637 | } 638 | 639 | 640 | - (void)notifyForSegmentChangeToIndex:(NSInteger)index { 641 | if (self.superview) { 642 | [self sendActionsForControlEvents:UIControlEventValueChanged]; 643 | if (self.indexChangeBlock) { 644 | self.indexChangeBlock(index); 645 | } 646 | } 647 | } 648 | 649 | #pragma mark - redPoint 650 | - (void)setInset:(UIEdgeInsets)inset forSegmentRedPointAtIndex:(NSUInteger)index{ 651 | self.redPointInsetsDic[@(index).stringValue] = [NSValue valueWithUIEdgeInsets:inset]; 652 | if (index < self.contentLayerArray.count) { 653 | VOContentLayer *contentLayer = self.contentLayerArray[index]; 654 | contentLayer.redPointInsets = inset; 655 | } 656 | } 657 | 658 | -(void)setShow:(BOOL)show forSegmentRedPointAtIndex:(NSUInteger)index{ 659 | self.showRedPointDic[@(index).stringValue] = @(show); 660 | if (index < self.contentLayerArray.count) { 661 | VOContentLayer *contentLayer = self.contentLayerArray[index]; 662 | contentLayer.showRedPoint = show; 663 | } 664 | } 665 | 666 | - (BOOL)isSegmentRedPointShowAtIndex:(NSUInteger)index{ 667 | if (index < self.contentLayerArray.count) { 668 | VOContentLayer *contentLayer = self.contentLayerArray[index]; 669 | return contentLayer.showRedPoint; 670 | } 671 | return NO; 672 | } 673 | 674 | @end 675 | -------------------------------------------------------------------------------- /VOSegmentedControlDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // VOSegmentedControlDemo 4 | // 5 | // Created by Valo Lee on 14-11-19. 6 | // Copyright (c) 2014年 valo. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /VOSegmentedControlDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // VOSegmentedControlDemo 4 | // 5 | // Created by Valo Lee on 14-11-19. 6 | // Copyright (c) 2014年 valo. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "VOSegmentedControl.h" 11 | 12 | @interface ViewController () 13 | @property (weak, nonatomic) IBOutlet VOSegmentedControl *segmentControl5; 14 | 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | // Do any additional setup after loading the view, typically from a nib. 22 | VOSegmentedControl *segctrl1 = [[VOSegmentedControl alloc] initWithSegments:@[@{VOSegmentText: @"A"}, 23 | @{VOSegmentText: @"B"}, 24 | @{VOSegmentText: @"C"}, 25 | @{VOSegmentText: @"D"}, 26 | @{VOSegmentText: @"E"}, 27 | @{VOSegmentText: @"F"}, 28 | @{VOSegmentText: @"G"}, 29 | @{VOSegmentText: @"H"}, 30 | @{VOSegmentText: @"I"}]]; 31 | segctrl1.contentStyle = VOContentStyleTextAlone; 32 | segctrl1.indicatorStyle = VOSegCtrlIndicatorStyleBottomLine; 33 | segctrl1.backgroundColor = [UIColor groupTableViewBackgroundColor]; 34 | segctrl1.selectedBackgroundColor = segctrl1.backgroundColor; 35 | segctrl1.allowNoSelection = NO; 36 | segctrl1.frame = CGRectMake(10, 100, 300, 40); 37 | segctrl1.indicatorThickness = 4; 38 | segctrl1.tag = 1; 39 | [self.view addSubview:segctrl1]; 40 | [segctrl1 setIndexChangeBlock:^(NSInteger index) { 41 | NSLog(@"1: block --> %@", @(index)); 42 | }]; 43 | [segctrl1 addTarget:self action:@selector(segmentCtrlValuechange:) forControlEvents:UIControlEventValueChanged]; 44 | 45 | VOSegmentedControl *segctrl2 = [[VOSegmentedControl alloc] 46 | initWithSegments:@[@{VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 47 | @{VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 48 | @{VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 49 | @{VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 50 | @{VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 51 | @{VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 52 | @{VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 53 | @{VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 54 | @{VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}]]; 55 | segctrl2.contentStyle = VOContentStyleImageAlone; 56 | segctrl2.indicatorStyle = VOSegCtrlIndicatorStyleTopLine; 57 | segctrl2.backgroundColor = [UIColor groupTableViewBackgroundColor]; 58 | segctrl2.selectedBackgroundColor = segctrl2.backgroundColor; 59 | segctrl2.allowNoSelection = YES; 60 | segctrl2.frame = CGRectMake(10, 160, 300, 40); 61 | segctrl2.indicatorThickness = 4; 62 | segctrl2.indicatorCornerRadius = 2; 63 | segctrl2.tag = 2; 64 | segctrl2.selectedSegmentIndex = 7; 65 | [self.view addSubview:segctrl2]; 66 | [segctrl2 setIndexChangeBlock:^(NSInteger index) { 67 | NSLog(@"2: block --> %@", @(index)); 68 | }]; 69 | [segctrl2 addTarget:self action:@selector(segmentCtrlValuechange:) forControlEvents:UIControlEventValueChanged]; 70 | VOSegmentedControl *segctrl3 = [[VOSegmentedControl alloc] 71 | initWithSegments:@[@{VOSegmentText: @"A", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 72 | @{VOSegmentText: @"B", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 73 | @{VOSegmentText: @"C", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 74 | @{VOSegmentText: @"D", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 75 | @{VOSegmentText: @"E", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 76 | @{VOSegmentText: @"F", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 77 | @{VOSegmentText: @"G", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 78 | @{VOSegmentText: @"H", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 79 | @{VOSegmentText: @"I", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}]]; 80 | segctrl3.contentStyle = VOContentStyleImageRight; 81 | segctrl3.indicatorStyle = VOSegCtrlIndicatorStyleBox; 82 | segctrl3.backgroundColor = [UIColor groupTableViewBackgroundColor]; 83 | segctrl3.selectedBackgroundColor = segctrl3.backgroundColor; 84 | segctrl3.allowNoSelection = NO; 85 | segctrl3.frame = CGRectMake(10, 220, 300, 40); 86 | segctrl3.indicatorThickness = 2; 87 | segctrl3.indicatorCornerRadius = 20; 88 | segctrl3.tag = 3; 89 | [self.view addSubview:segctrl3]; 90 | [segctrl3 setIndexChangeBlock:^(NSInteger index) { 91 | NSLog(@"3: block --> %@", @(index)); 92 | }]; 93 | [segctrl3 addTarget:self action:@selector(segmentCtrlValuechange:) forControlEvents:UIControlEventValueChanged]; 94 | 95 | VOSegmentedControl *segctrl4 = [[VOSegmentedControl alloc] 96 | initWithSegments:@[@{VOSegmentText: @"A", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 97 | @{VOSegmentText: @"B", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 98 | @{VOSegmentText: @"C", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 99 | @{VOSegmentText: @"D", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 100 | @{VOSegmentText: @"E", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 101 | @{VOSegmentText: @"F", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 102 | @{VOSegmentText: @"G", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 103 | @{VOSegmentText: @"H", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 104 | @{VOSegmentText: @"I", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}]]; 105 | segctrl4.contentStyle = VOContentStyleImageBottom; 106 | segctrl4.indicatorStyle = VOSegCtrlIndicatorStyleBox; 107 | segctrl4.animationType = VOSegCtrlAnimationTypeSmooth; 108 | segctrl4.backgroundColor = [UIColor groupTableViewBackgroundColor]; 109 | segctrl4.selectedBackgroundColor = segctrl4.backgroundColor; 110 | segctrl4.allowNoSelection = NO; 111 | segctrl4.frame = CGRectMake(10, 280, 300, 60); 112 | segctrl4.indicatorCornerRadius = 30; 113 | segctrl4.tag = 4; 114 | [self.view addSubview:segctrl4]; 115 | [segctrl4 setIndexChangeBlock:^(NSInteger index) { 116 | NSLog(@"4: block --> %@", @(index)); 117 | }]; 118 | [segctrl4 addTarget:self action:@selector(segmentCtrlValuechange:) forControlEvents:UIControlEventValueChanged]; 119 | 120 | self.segmentControl5.segments = @[@{VOSegmentText: @"A", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 121 | @{VOSegmentText: @"B", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 122 | @{VOSegmentText: @"C", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 123 | @{VOSegmentText: @"D", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 124 | @{VOSegmentText: @"E", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 125 | @{VOSegmentText: @"F", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 126 | @{VOSegmentText: @"G", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 127 | @{VOSegmentText: @"H", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}, 128 | @{VOSegmentText: @"I", VOSegmentImage: @"open", VOSegmentSelectedImage: @"close"}]; 129 | } 130 | 131 | - (void)didReceiveMemoryWarning { 132 | [super didReceiveMemoryWarning]; 133 | // Dispose of any resources that can be recreated. 134 | } 135 | 136 | - (IBAction)segmentCtrlValuechange: (VOSegmentedControl *)segmentCtrl{ 137 | NSLog(@"%@: value --> %@",@(segmentCtrl.tag), @(segmentCtrl.selectedSegmentIndex)); 138 | } 139 | 140 | 141 | @end 142 | -------------------------------------------------------------------------------- /VOSegmentedControlDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // VOSegmentedControlDemo 4 | // 5 | // Created by Valo Lee on 14-11-19. 6 | // Copyright (c) 2014年 valo. 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 | -------------------------------------------------------------------------------- /VOSegmentedControlDemoTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.valo.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /VOSegmentedControlDemoTests/VOSegmentedControlDemoTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // VOSegmentedControlDemoTests.m 3 | // VOSegmentedControlDemoTests 4 | // 5 | // Created by Valo Lee on 14-11-19. 6 | // Copyright (c) 2014年 valo. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface VOSegmentedControlDemoTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation VOSegmentedControlDemoTests 17 | 18 | - (void)setUp { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | [super tearDown]; 26 | } 27 | 28 | - (void)testExample { 29 | // This is an example of a functional test case. 30 | XCTAssert(YES, @"Pass"); 31 | } 32 | 33 | - (void)testPerformanceExample { 34 | // This is an example of a performance test case. 35 | [self measureBlock:^{ 36 | // Put the code you want to measure the time of here. 37 | }]; 38 | } 39 | 40 | @end 41 | --------------------------------------------------------------------------------