├── .gitignore ├── LICENSE ├── LxThroughPointsBezier-Swift ├── LxThroughPointsBezier-Swift.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata └── LxThroughPointsBezier-Swift │ ├── AppDelegate.swift │ ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard │ ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Info.plist │ ├── PointView.swift │ └── ViewController.swift ├── README.md ├── UIBezierPath+LxThroughPointsBezier.swift └── demo.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | # Pods/ 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /LxThroughPointsBezier-Swift/LxThroughPointsBezier-Swift.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 3594859F1A77E6AF0011B339 /* UIBezierPath+LxThroughPointsBezier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3594859E1A77E6AF0011B339 /* UIBezierPath+LxThroughPointsBezier.swift */; }; 11 | 35C2E3591A768F2A007C1C1A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C2E3581A768F2A007C1C1A /* AppDelegate.swift */; }; 12 | 35C2E35B1A768F2A007C1C1A /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C2E35A1A768F2A007C1C1A /* ViewController.swift */; }; 13 | 35C2E35E1A768F2A007C1C1A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 35C2E35C1A768F2A007C1C1A /* Main.storyboard */; }; 14 | 35C2E3601A768F2A007C1C1A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 35C2E35F1A768F2A007C1C1A /* Images.xcassets */; }; 15 | 35C2E3631A768F2A007C1C1A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 35C2E3611A768F2A007C1C1A /* LaunchScreen.xib */; }; 16 | B63DA9521B4ACCC700B3C66B /* PointView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B63DA9511B4ACCC700B3C66B /* PointView.swift */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 3594859E1A77E6AF0011B339 /* UIBezierPath+LxThroughPointsBezier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIBezierPath+LxThroughPointsBezier.swift"; path = "../../UIBezierPath+LxThroughPointsBezier.swift"; sourceTree = ""; }; 21 | 35C2E3531A768F2A007C1C1A /* LxThroughPointsBezier-Swift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "LxThroughPointsBezier-Swift.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | 35C2E3571A768F2A007C1C1A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 23 | 35C2E3581A768F2A007C1C1A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 24 | 35C2E35A1A768F2A007C1C1A /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 25 | 35C2E35D1A768F2A007C1C1A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 26 | 35C2E35F1A768F2A007C1C1A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 27 | 35C2E3621A768F2A007C1C1A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 28 | B63DA9511B4ACCC700B3C66B /* PointView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PointView.swift; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | 35C2E3501A768F2A007C1C1A /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | 35C2E34A1A768F2A007C1C1A = { 43 | isa = PBXGroup; 44 | children = ( 45 | 35C2E3551A768F2A007C1C1A /* LxThroughPointsBezier-Swift */, 46 | 35C2E3541A768F2A007C1C1A /* Products */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | 35C2E3541A768F2A007C1C1A /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | 35C2E3531A768F2A007C1C1A /* LxThroughPointsBezier-Swift.app */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | 35C2E3551A768F2A007C1C1A /* LxThroughPointsBezier-Swift */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 3594859E1A77E6AF0011B339 /* UIBezierPath+LxThroughPointsBezier.swift */, 62 | 35C2E3581A768F2A007C1C1A /* AppDelegate.swift */, 63 | 35C2E35A1A768F2A007C1C1A /* ViewController.swift */, 64 | B63DA9511B4ACCC700B3C66B /* PointView.swift */, 65 | 35C2E3561A768F2A007C1C1A /* Supporting Files */, 66 | ); 67 | path = "LxThroughPointsBezier-Swift"; 68 | sourceTree = ""; 69 | }; 70 | 35C2E3561A768F2A007C1C1A /* Supporting Files */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | 35C2E3611A768F2A007C1C1A /* LaunchScreen.xib */, 74 | 35C2E35C1A768F2A007C1C1A /* Main.storyboard */, 75 | 35C2E35F1A768F2A007C1C1A /* Images.xcassets */, 76 | 35C2E3571A768F2A007C1C1A /* Info.plist */, 77 | ); 78 | name = "Supporting Files"; 79 | sourceTree = ""; 80 | }; 81 | /* End PBXGroup section */ 82 | 83 | /* Begin PBXNativeTarget section */ 84 | 35C2E3521A768F2A007C1C1A /* LxThroughPointsBezier-Swift */ = { 85 | isa = PBXNativeTarget; 86 | buildConfigurationList = 35C2E3721A768F2A007C1C1A /* Build configuration list for PBXNativeTarget "LxThroughPointsBezier-Swift" */; 87 | buildPhases = ( 88 | 35C2E34F1A768F2A007C1C1A /* Sources */, 89 | 35C2E3501A768F2A007C1C1A /* Frameworks */, 90 | 35C2E3511A768F2A007C1C1A /* Resources */, 91 | ); 92 | buildRules = ( 93 | ); 94 | dependencies = ( 95 | ); 96 | name = "LxThroughPointsBezier-Swift"; 97 | productName = "LxThroughPointsBezier-Swift"; 98 | productReference = 35C2E3531A768F2A007C1C1A /* LxThroughPointsBezier-Swift.app */; 99 | productType = "com.apple.product-type.application"; 100 | }; 101 | /* End PBXNativeTarget section */ 102 | 103 | /* Begin PBXProject section */ 104 | 35C2E34B1A768F2A007C1C1A /* Project object */ = { 105 | isa = PBXProject; 106 | attributes = { 107 | LastUpgradeCheck = 0610; 108 | ORGANIZATIONNAME = "Gener-health-li.x"; 109 | TargetAttributes = { 110 | 35C2E3521A768F2A007C1C1A = { 111 | CreatedOnToolsVersion = 6.1.1; 112 | }; 113 | }; 114 | }; 115 | buildConfigurationList = 35C2E34E1A768F2A007C1C1A /* Build configuration list for PBXProject "LxThroughPointsBezier-Swift" */; 116 | compatibilityVersion = "Xcode 3.2"; 117 | developmentRegion = English; 118 | hasScannedForEncodings = 0; 119 | knownRegions = ( 120 | en, 121 | Base, 122 | ); 123 | mainGroup = 35C2E34A1A768F2A007C1C1A; 124 | productRefGroup = 35C2E3541A768F2A007C1C1A /* Products */; 125 | projectDirPath = ""; 126 | projectRoot = ""; 127 | targets = ( 128 | 35C2E3521A768F2A007C1C1A /* LxThroughPointsBezier-Swift */, 129 | ); 130 | }; 131 | /* End PBXProject section */ 132 | 133 | /* Begin PBXResourcesBuildPhase section */ 134 | 35C2E3511A768F2A007C1C1A /* Resources */ = { 135 | isa = PBXResourcesBuildPhase; 136 | buildActionMask = 2147483647; 137 | files = ( 138 | 35C2E35E1A768F2A007C1C1A /* Main.storyboard in Resources */, 139 | 35C2E3631A768F2A007C1C1A /* LaunchScreen.xib in Resources */, 140 | 35C2E3601A768F2A007C1C1A /* Images.xcassets in Resources */, 141 | ); 142 | runOnlyForDeploymentPostprocessing = 0; 143 | }; 144 | /* End PBXResourcesBuildPhase section */ 145 | 146 | /* Begin PBXSourcesBuildPhase section */ 147 | 35C2E34F1A768F2A007C1C1A /* Sources */ = { 148 | isa = PBXSourcesBuildPhase; 149 | buildActionMask = 2147483647; 150 | files = ( 151 | 35C2E35B1A768F2A007C1C1A /* ViewController.swift in Sources */, 152 | 35C2E3591A768F2A007C1C1A /* AppDelegate.swift in Sources */, 153 | 3594859F1A77E6AF0011B339 /* UIBezierPath+LxThroughPointsBezier.swift in Sources */, 154 | B63DA9521B4ACCC700B3C66B /* PointView.swift in Sources */, 155 | ); 156 | runOnlyForDeploymentPostprocessing = 0; 157 | }; 158 | /* End PBXSourcesBuildPhase section */ 159 | 160 | /* Begin PBXVariantGroup section */ 161 | 35C2E35C1A768F2A007C1C1A /* Main.storyboard */ = { 162 | isa = PBXVariantGroup; 163 | children = ( 164 | 35C2E35D1A768F2A007C1C1A /* Base */, 165 | ); 166 | name = Main.storyboard; 167 | sourceTree = ""; 168 | }; 169 | 35C2E3611A768F2A007C1C1A /* LaunchScreen.xib */ = { 170 | isa = PBXVariantGroup; 171 | children = ( 172 | 35C2E3621A768F2A007C1C1A /* Base */, 173 | ); 174 | name = LaunchScreen.xib; 175 | sourceTree = ""; 176 | }; 177 | /* End PBXVariantGroup section */ 178 | 179 | /* Begin XCBuildConfiguration section */ 180 | 35C2E3701A768F2A007C1C1A /* Debug */ = { 181 | isa = XCBuildConfiguration; 182 | buildSettings = { 183 | ALWAYS_SEARCH_USER_PATHS = NO; 184 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 185 | CLANG_CXX_LIBRARY = "libc++"; 186 | CLANG_ENABLE_MODULES = YES; 187 | CLANG_ENABLE_OBJC_ARC = YES; 188 | CLANG_WARN_BOOL_CONVERSION = YES; 189 | CLANG_WARN_CONSTANT_CONVERSION = YES; 190 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 191 | CLANG_WARN_EMPTY_BODY = YES; 192 | CLANG_WARN_ENUM_CONVERSION = YES; 193 | CLANG_WARN_INT_CONVERSION = YES; 194 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 195 | CLANG_WARN_UNREACHABLE_CODE = YES; 196 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 197 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 198 | COPY_PHASE_STRIP = NO; 199 | ENABLE_STRICT_OBJC_MSGSEND = YES; 200 | GCC_C_LANGUAGE_STANDARD = gnu99; 201 | GCC_DYNAMIC_NO_PIC = NO; 202 | GCC_OPTIMIZATION_LEVEL = 0; 203 | GCC_PREPROCESSOR_DEFINITIONS = ( 204 | "DEBUG=1", 205 | "$(inherited)", 206 | ); 207 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 208 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 209 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 210 | GCC_WARN_UNDECLARED_SELECTOR = YES; 211 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 212 | GCC_WARN_UNUSED_FUNCTION = YES; 213 | GCC_WARN_UNUSED_VARIABLE = YES; 214 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 215 | MTL_ENABLE_DEBUG_INFO = YES; 216 | ONLY_ACTIVE_ARCH = YES; 217 | SDKROOT = iphoneos; 218 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 219 | TARGETED_DEVICE_FAMILY = "1,2"; 220 | }; 221 | name = Debug; 222 | }; 223 | 35C2E3711A768F2A007C1C1A /* Release */ = { 224 | isa = XCBuildConfiguration; 225 | buildSettings = { 226 | ALWAYS_SEARCH_USER_PATHS = NO; 227 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 228 | CLANG_CXX_LIBRARY = "libc++"; 229 | CLANG_ENABLE_MODULES = YES; 230 | CLANG_ENABLE_OBJC_ARC = YES; 231 | CLANG_WARN_BOOL_CONVERSION = YES; 232 | CLANG_WARN_CONSTANT_CONVERSION = YES; 233 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 234 | CLANG_WARN_EMPTY_BODY = YES; 235 | CLANG_WARN_ENUM_CONVERSION = YES; 236 | CLANG_WARN_INT_CONVERSION = YES; 237 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 238 | CLANG_WARN_UNREACHABLE_CODE = YES; 239 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 240 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 241 | COPY_PHASE_STRIP = YES; 242 | ENABLE_NS_ASSERTIONS = NO; 243 | ENABLE_STRICT_OBJC_MSGSEND = YES; 244 | GCC_C_LANGUAGE_STANDARD = gnu99; 245 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 246 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 247 | GCC_WARN_UNDECLARED_SELECTOR = YES; 248 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 249 | GCC_WARN_UNUSED_FUNCTION = YES; 250 | GCC_WARN_UNUSED_VARIABLE = YES; 251 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 252 | MTL_ENABLE_DEBUG_INFO = NO; 253 | SDKROOT = iphoneos; 254 | TARGETED_DEVICE_FAMILY = "1,2"; 255 | VALIDATE_PRODUCT = YES; 256 | }; 257 | name = Release; 258 | }; 259 | 35C2E3731A768F2A007C1C1A /* Debug */ = { 260 | isa = XCBuildConfiguration; 261 | buildSettings = { 262 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 263 | INFOPLIST_FILE = "LxThroughPointsBezier-Swift/Info.plist"; 264 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 265 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 266 | PRODUCT_NAME = "$(TARGET_NAME)"; 267 | }; 268 | name = Debug; 269 | }; 270 | 35C2E3741A768F2A007C1C1A /* Release */ = { 271 | isa = XCBuildConfiguration; 272 | buildSettings = { 273 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 274 | INFOPLIST_FILE = "LxThroughPointsBezier-Swift/Info.plist"; 275 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 276 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 277 | PRODUCT_NAME = "$(TARGET_NAME)"; 278 | }; 279 | name = Release; 280 | }; 281 | /* End XCBuildConfiguration section */ 282 | 283 | /* Begin XCConfigurationList section */ 284 | 35C2E34E1A768F2A007C1C1A /* Build configuration list for PBXProject "LxThroughPointsBezier-Swift" */ = { 285 | isa = XCConfigurationList; 286 | buildConfigurations = ( 287 | 35C2E3701A768F2A007C1C1A /* Debug */, 288 | 35C2E3711A768F2A007C1C1A /* Release */, 289 | ); 290 | defaultConfigurationIsVisible = 0; 291 | defaultConfigurationName = Release; 292 | }; 293 | 35C2E3721A768F2A007C1C1A /* Build configuration list for PBXNativeTarget "LxThroughPointsBezier-Swift" */ = { 294 | isa = XCConfigurationList; 295 | buildConfigurations = ( 296 | 35C2E3731A768F2A007C1C1A /* Debug */, 297 | 35C2E3741A768F2A007C1C1A /* Release */, 298 | ); 299 | defaultConfigurationIsVisible = 0; 300 | defaultConfigurationName = Release; 301 | }; 302 | /* End XCConfigurationList section */ 303 | }; 304 | rootObject = 35C2E34B1A768F2A007C1C1A /* Project object */; 305 | } 306 | -------------------------------------------------------------------------------- /LxThroughPointsBezier-Swift/LxThroughPointsBezier-Swift.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LxThroughPointsBezier-Swift/LxThroughPointsBezier-Swift/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // LxThroughPointsBezier-Swift 4 | // 5 | 6 | import UIKit 7 | 8 | @UIApplicationMain 9 | class AppDelegate: UIResponder, UIApplicationDelegate { 10 | 11 | var window: UIWindow? 12 | } 13 | 14 | -------------------------------------------------------------------------------- /LxThroughPointsBezier-Swift/LxThroughPointsBezier-Swift/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 | -------------------------------------------------------------------------------- /LxThroughPointsBezier-Swift/LxThroughPointsBezier-Swift/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 | -------------------------------------------------------------------------------- /LxThroughPointsBezier-Swift/LxThroughPointsBezier-Swift/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /LxThroughPointsBezier-Swift/LxThroughPointsBezier-Swift/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.gener-tech-bj.LxFTPRequestDemo.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /LxThroughPointsBezier-Swift/LxThroughPointsBezier-Swift/PointView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PointView.swift 3 | // LxThroughPointsBezier-Swift 4 | // 5 | 6 | import UIKit 7 | 8 | private let RADIUS: CGFloat = 5 9 | 10 | class PointView: UIControl { 11 | 12 | class func aInstance() -> PointView { 13 | 14 | let aInstance = PointView(frame: CGRect(origin: CGPointZero, size: CGSize(width: RADIUS * 2, height: RADIUS * 2))) 15 | aInstance.layer.cornerRadius = RADIUS 16 | aInstance.layer.masksToBounds = true 17 | aInstance.backgroundColor = UIColor.magentaColor() 18 | aInstance.addTarget(aInstance, action: Selector("touchDragInside:withEvent:"), forControlEvents: .TouchDragInside) 19 | return aInstance 20 | } 21 | 22 | var dragCallBack = { (pointView: PointView) -> Void in } 23 | 24 | func touchDragInside(pointView: PointView, withEvent event: UIEvent) { 25 | 26 | for touch in event.allTouches()! { 27 | 28 | pointView.center = (touch as! UITouch).locationInView(superview) 29 | dragCallBack(self) 30 | return 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /LxThroughPointsBezier-Swift/LxThroughPointsBezier-Swift/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // LxThroughPointsBezier-Swift 4 | // 5 | 6 | import UIKit 7 | 8 | class ViewController: UIViewController { 9 | 10 | let _curve = UIBezierPath() 11 | let _shapeLayer = CAShapeLayer() 12 | var _pointViewArray = [PointView]() 13 | 14 | override func viewDidLoad() { 15 | super.viewDidLoad() 16 | 17 | let slider = UISlider() 18 | slider.minimumValue = 0 19 | slider.maximumValue = 1.4 20 | slider.value = 0.7 21 | slider.addTarget(self, action: "sliderValueChanged:", forControlEvents: .ValueChanged) 22 | view.addSubview(slider) 23 | 24 | slider.setTranslatesAutoresizingMaskIntoConstraints(false) 25 | 26 | let sliderHorizontalConstraints = NSLayoutConstraint.constraintsWithVisualFormat("H:|-[slider]-|", options: .DirectionLeadingToTrailing, metrics: nil, views: ["slider":slider]) 27 | let sliderVerticalConstraints = NSLayoutConstraint.constraintsWithVisualFormat("V:|-topMargin-[slider(==sliderHeight)]", options: .DirectionLeadingToTrailing, metrics: ["sliderHeight":6, "topMargin":60], views: ["slider":slider]) 28 | 29 | view.addConstraints(sliderHorizontalConstraints) 30 | view.addConstraints(sliderVerticalConstraints) 31 | 32 | var pointArray = [CGPoint]() 33 | 34 | for i in 0 ..< 6 { 35 | 36 | let pointView = PointView.aInstance() 37 | pointView.center = CGPoint(x: i * 60 + 30, y: 420) 38 | pointView.dragCallBack = { [unowned self] (pointView: PointView) -> Void in 39 | 40 | self.sliderValueChanged(slider) 41 | } 42 | view.addSubview(pointView) 43 | _pointViewArray.append(pointView) 44 | 45 | pointArray.append(pointView.center) 46 | } 47 | 48 | _curve.moveToPoint(_pointViewArray.first!.center) 49 | _curve.addBezierThrough(points: pointArray) 50 | 51 | _shapeLayer.strokeColor = UIColor.blueColor().CGColor 52 | _shapeLayer.fillColor = nil 53 | _shapeLayer.lineWidth = 3 54 | _shapeLayer.path = _curve.CGPath 55 | _shapeLayer.lineCap = kCALineCapRound 56 | view.layer.addSublayer(_shapeLayer) 57 | } 58 | 59 | func sliderValueChanged(slider: UISlider) { 60 | 61 | _curve.removeAllPoints() 62 | _curve.contractionFactor = CGFloat(slider.value) 63 | 64 | _curve.moveToPoint(_pointViewArray.first!.center) 65 | 66 | var pointArray = [CGPoint]() 67 | for pointView in _pointViewArray { 68 | 69 | pointArray.append(pointView.center) 70 | } 71 | _curve.addBezierThrough(points: pointArray) 72 | 73 | _shapeLayer.path = _curve.CGPath 74 | } 75 | } 76 | 77 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LxThroughPointsBezier-Swift 2 | An ideal iOS library using swift programming language. Draw a smooth curve through several points you designated. The curve‘s bend level is adjustable. 3 | Installation 4 | ------------ 5 | You only need drag UIBezierPath+LxThroughPointsBezier.swift to your project. 6 | Support 7 | ------------ 8 | Minimum support iOS version: iOS 5.0 9 | Usage 10 | ----------- 11 | ### 12 | ```swift 13 | var _points = [CGPoint]() 14 | 15 | let point1 = CGPoint(x: 30, y: 210) 16 | let point2 = CGPoint(x: 90, y: 120) 17 | let point3 = CGPoint(x: 120, y: 200) 18 | let point4 = CGPoint(x: 160, y: 240) 19 | let point5 = CGPoint(x: 210, y: 160) 20 | let point6 = CGPoint(x: 240, y: 300) 21 | let point7 = CGPoint(x: 290, y: 140) 22 | 23 | _points.append(point1) 24 | _points.append(point2) 25 | _points.append(point3) 26 | _points.append(point4) 27 | _points.append(point5) 28 | _points.append(point6) 29 | _points.append(point7) 30 | 31 | let _curve = UIBezierPath() 32 | 33 | _curve.contractionFactor = CGFloat(0.7) 34 | _curve.moveToPoint(point1) 35 | _curve.addBezierThrough(points: _points) 36 | 37 | let _shapeLayer = CAShapeLayer() 38 | 39 | _shapeLayer.strokeColor = UIColor.blueColor().CGColor 40 | _shapeLayer.fillColor = nil 41 | _shapeLayer.lineWidth = 3 42 | _shapeLayer.path = _curve.CGPath 43 | _shapeLayer.lineCap = kCALineCapRound 44 | view.layer.addSublayer(_shapeLayer) 45 | ``` 46 | Be careful 47 | ----------- 48 | The good bend level is about 0.6 ~ 0.8. The default and recommended value is 0.7. 49 | You must give at least 1 point for drawing the curve. 50 | Effect 51 | ----------- 52 | * ![demo](demo.gif) 53 | 54 | License 55 | ----------- 56 | LxThroughPointsBezier-Swift is available under the Apache License 2.0. See the LICENSE file for more info. 57 | -------------------------------------------------------------------------------- /UIBezierPath+LxThroughPointsBezier.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIBezierPath+LxThroughPointsBezier.swift 3 | // LxThroughPointsBezier-Swift 4 | // 5 | 6 | import Foundation 7 | import UIKit 8 | 9 | private var _contractionFactor: CGFloat = 0.7 10 | 11 | extension UIBezierPath { 12 | 13 | /// The curve‘s bend level. The good value is about 0.6 ~ 0.8. The default and recommended value is 0.7. 14 | var contractionFactor: CGFloat { 15 | get { 16 | return _contractionFactor 17 | } 18 | set { 19 | _contractionFactor = max(0, newValue) 20 | } 21 | } 22 | 23 | /** 24 | @param: points Points your bezier wants to through. You must give at least 1 point (different from current point) for drawing curve. 25 | */ 26 | func addBezierThrough(#points: [CGPoint]) { 27 | 28 | assert(points.count > 0, "You must give at least 1 point for drawing the bezier."); 29 | 30 | if points.count < 3 { 31 | 32 | switch points.count { 33 | 34 | case 1: 35 | addLineToPoint(points[0]) 36 | case 2: 37 | addLineToPoint(points[1]) 38 | default: 39 | break 40 | } 41 | return 42 | } 43 | 44 | var previousPoint = CGPointZero 45 | 46 | var previousCenterPoint = CGPointZero 47 | var centerPoint = CGPointZero 48 | var centerPointDistance = CGFloat() 49 | 50 | var obliqueAngle = CGFloat() 51 | 52 | var previousControlPoint1 = CGPointZero 53 | var previousControlPoint2 = CGPointZero 54 | var controlPoint1 = CGPointZero 55 | 56 | for var i = 0; i < points.count; i++ { 57 | 58 | let pointI = points[i] 59 | 60 | if i > 0 { 61 | 62 | previousCenterPoint = CenterPointOf(currentPoint, previousPoint) 63 | centerPoint = CenterPointOf(previousPoint, pointI) 64 | 65 | centerPointDistance = DistanceBetween(previousCenterPoint, centerPoint) 66 | 67 | obliqueAngle = ObliqueAngleOfStraightThrough(point1:centerPoint, point2:previousCenterPoint) 68 | 69 | previousControlPoint2 = CGPoint(x: previousPoint.x - 0.5 * contractionFactor * centerPointDistance * cos(obliqueAngle), y: previousPoint.y - 0.5 * contractionFactor * centerPointDistance * sin(obliqueAngle)) 70 | controlPoint1 = CGPoint(x: previousPoint.x + 0.5 * contractionFactor * centerPointDistance * cos(obliqueAngle), y: previousPoint.y + 0.5 * contractionFactor * centerPointDistance * sin(obliqueAngle)) 71 | } 72 | 73 | switch i { 74 | 75 | case 1 : 76 | 77 | addQuadCurveToPoint(previousPoint, controlPoint: previousControlPoint2) 78 | 79 | case 2 ..< points.count - 1 : 80 | 81 | addCurveToPoint(previousPoint, controlPoint1: previousControlPoint1, controlPoint2: previousControlPoint2) 82 | 83 | case points.count - 1 : 84 | 85 | addCurveToPoint(previousPoint, controlPoint1: previousControlPoint1, controlPoint2: previousControlPoint2) 86 | addQuadCurveToPoint(pointI, controlPoint: controlPoint1) 87 | 88 | default: 89 | break 90 | } 91 | 92 | previousControlPoint1 = controlPoint1 93 | previousPoint = pointI 94 | } 95 | } 96 | } 97 | 98 | func ObliqueAngleOfStraightThrough(#point1: CGPoint, #point2: CGPoint) -> CGFloat { // [-π/2, 3π/2) 99 | 100 | var obliqueRatio: CGFloat = 0 101 | var obliqueAngle: CGFloat = 0 102 | 103 | if (point1.x > point2.x) { 104 | 105 | obliqueRatio = (point2.y - point1.y) / (point2.x - point1.x) 106 | obliqueAngle = atan(obliqueRatio) 107 | } 108 | else if (point1.x < point2.x) { 109 | 110 | obliqueRatio = (point2.y - point1.y) / (point2.x - point1.x) 111 | obliqueAngle = CGFloat(M_PI) + atan(obliqueRatio) 112 | } 113 | else if (point2.y - point1.y >= 0) { 114 | 115 | obliqueAngle = CGFloat(M_PI)/2 116 | } 117 | else { 118 | obliqueAngle = -CGFloat(M_PI)/2 119 | } 120 | 121 | return obliqueAngle 122 | } 123 | 124 | func ControlPointForTheBezierCanThrough(#point1: CGPoint, #point2: CGPoint, #point3: CGPoint) -> CGPoint { 125 | 126 | return CGPoint(x: (2 * point2.x - (point1.x + point3.x) / 2), y: (2 * point2.y - (point1.y + point3.y) / 2)); 127 | } 128 | 129 | func DistanceBetween(point1: CGPoint, point2: CGPoint) -> CGFloat { 130 | 131 | return sqrt((point1.x - point2.x) * (point1.x - point2.x) + (point1.y - point2.y) * (point1.y - point2.y)) 132 | } 133 | 134 | func CenterPointOf(point1: CGPoint, point2: CGPoint) -> CGPoint { 135 | 136 | return CGPoint(x: (point1.x + point2.x) / 2, y: (point1.y + point2.y) / 2) 137 | } -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeveloperLx/LxThroughPointsBezier-Swift/fa75e8fd7f388af3bf1fcc6440bc2566ad2b130c/demo.gif --------------------------------------------------------------------------------