├── .gitignore ├── LICENSE ├── NanoFrame.podspec ├── NanoFrame.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── NanoFrame ├── CALayer+NanoFrame.swift ├── Info.plist ├── NanoFrame.h ├── UIColor+NanoFrame.swift ├── UIImage+NanoFrame.swift └── UIView+NanoFrame.swift ├── NanoFrameTests ├── Info.plist └── NanoFrameTests.swift ├── README.md └── composite.png /.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 | 28 | .DS_Store 29 | .idea/ 30 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /NanoFrame.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "NanoFrame" 3 | s.version = "1.0.8" 4 | s.summary = "A minimal frame-based layout and UIKit additions." 5 | s.homepage = "https://github.com/appsquickly/NanoFrame" 6 | s.license = { :type => 'Apache2.0', :file => 'LICENSE' } 7 | s.author = { "Jasper Blues" => "jasper@appsquick.ly" } 8 | s.source = { :git => "https://github.com/appsquickly/NanoFrame.git", :tag => s.version.to_s } 9 | s.platform = :ios 10 | s.source_files = 'Source/**/*.{h,m}' 11 | s.frameworks = 'QuartzCore' 12 | s.requires_arc = true 13 | s.ios.deployment_target = '9.0' 14 | s.source_files = 'NanoFrame/*.swift' 15 | s.swift_version = '5.1' 16 | end 17 | -------------------------------------------------------------------------------- /NanoFrame.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 6B48C172258D7DFA00E8BB9C /* NanoFrame.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B48C168258D7DF900E8BB9C /* NanoFrame.framework */; }; 11 | 6B48C177258D7DFA00E8BB9C /* NanoFrameTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B48C176258D7DFA00E8BB9C /* NanoFrameTests.swift */; }; 12 | 6B48C179258D7DFA00E8BB9C /* NanoFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B48C16B258D7DF900E8BB9C /* NanoFrame.h */; settings = {ATTRIBUTES = (Public, ); }; }; 13 | BA79833368388840ACBE6904 /* UIColor+NanoFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA798DE91D1B861CA2C233F5 /* UIColor+NanoFrame.swift */; }; 14 | BA79842FA052048F7A7E12B3 /* CALayer+NanoFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA798350EA9608D1DEB9EB0C /* CALayer+NanoFrame.swift */; }; 15 | BA798832A5D7BC8C4604A9FA /* UIView+NanoFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA798A0E4D1EF606C3944D26 /* UIView+NanoFrame.swift */; }; 16 | BA798C4C8491E166D9782703 /* UIImage+NanoFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA7983586228886BA16FBA76 /* UIImage+NanoFrame.swift */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXContainerItemProxy section */ 20 | 6B48C173258D7DFA00E8BB9C /* PBXContainerItemProxy */ = { 21 | isa = PBXContainerItemProxy; 22 | containerPortal = 6B48C15F258D7DF900E8BB9C /* Project object */; 23 | proxyType = 1; 24 | remoteGlobalIDString = 6B48C167258D7DF900E8BB9C; 25 | remoteInfo = NanoFrame; 26 | }; 27 | /* End PBXContainerItemProxy section */ 28 | 29 | /* Begin PBXFileReference section */ 30 | 6B48C168258D7DF900E8BB9C /* NanoFrame.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = NanoFrame.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 31 | 6B48C16B258D7DF900E8BB9C /* NanoFrame.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NanoFrame.h; sourceTree = ""; }; 32 | 6B48C16C258D7DF900E8BB9C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 33 | 6B48C171258D7DFA00E8BB9C /* NanoFrameTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NanoFrameTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 34 | 6B48C176258D7DFA00E8BB9C /* NanoFrameTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NanoFrameTests.swift; sourceTree = ""; }; 35 | 6B48C178258D7DFA00E8BB9C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 36 | BA798350EA9608D1DEB9EB0C /* CALayer+NanoFrame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CALayer+NanoFrame.swift"; sourceTree = ""; }; 37 | BA7983586228886BA16FBA76 /* UIImage+NanoFrame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+NanoFrame.swift"; sourceTree = ""; }; 38 | BA798A0E4D1EF606C3944D26 /* UIView+NanoFrame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+NanoFrame.swift"; sourceTree = ""; }; 39 | BA798DE91D1B861CA2C233F5 /* UIColor+NanoFrame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIColor+NanoFrame.swift"; sourceTree = ""; }; 40 | /* End PBXFileReference section */ 41 | 42 | /* Begin PBXFrameworksBuildPhase section */ 43 | 6B48C165258D7DF900E8BB9C /* Frameworks */ = { 44 | isa = PBXFrameworksBuildPhase; 45 | buildActionMask = 2147483647; 46 | files = ( 47 | ); 48 | runOnlyForDeploymentPostprocessing = 0; 49 | }; 50 | 6B48C16E258D7DFA00E8BB9C /* Frameworks */ = { 51 | isa = PBXFrameworksBuildPhase; 52 | buildActionMask = 2147483647; 53 | files = ( 54 | 6B48C172258D7DFA00E8BB9C /* NanoFrame.framework in Frameworks */, 55 | ); 56 | runOnlyForDeploymentPostprocessing = 0; 57 | }; 58 | /* End PBXFrameworksBuildPhase section */ 59 | 60 | /* Begin PBXGroup section */ 61 | 6B48C15E258D7DF900E8BB9C = { 62 | isa = PBXGroup; 63 | children = ( 64 | 6B48C16A258D7DF900E8BB9C /* NanoFrame */, 65 | 6B48C175258D7DFA00E8BB9C /* NanoFrameTests */, 66 | 6B48C169258D7DF900E8BB9C /* Products */, 67 | ); 68 | sourceTree = ""; 69 | }; 70 | 6B48C169258D7DF900E8BB9C /* Products */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | 6B48C168258D7DF900E8BB9C /* NanoFrame.framework */, 74 | 6B48C171258D7DFA00E8BB9C /* NanoFrameTests.xctest */, 75 | ); 76 | name = Products; 77 | sourceTree = ""; 78 | }; 79 | 6B48C16A258D7DF900E8BB9C /* NanoFrame */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | 6B48C16B258D7DF900E8BB9C /* NanoFrame.h */, 83 | 6B48C16C258D7DF900E8BB9C /* Info.plist */, 84 | BA798DE91D1B861CA2C233F5 /* UIColor+NanoFrame.swift */, 85 | BA798350EA9608D1DEB9EB0C /* CALayer+NanoFrame.swift */, 86 | BA7983586228886BA16FBA76 /* UIImage+NanoFrame.swift */, 87 | BA798A0E4D1EF606C3944D26 /* UIView+NanoFrame.swift */, 88 | ); 89 | path = NanoFrame; 90 | sourceTree = ""; 91 | }; 92 | 6B48C175258D7DFA00E8BB9C /* NanoFrameTests */ = { 93 | isa = PBXGroup; 94 | children = ( 95 | 6B48C176258D7DFA00E8BB9C /* NanoFrameTests.swift */, 96 | 6B48C178258D7DFA00E8BB9C /* Info.plist */, 97 | ); 98 | path = NanoFrameTests; 99 | sourceTree = ""; 100 | }; 101 | /* End PBXGroup section */ 102 | 103 | /* Begin PBXHeadersBuildPhase section */ 104 | 6B48C163258D7DF900E8BB9C /* Headers */ = { 105 | isa = PBXHeadersBuildPhase; 106 | buildActionMask = 2147483647; 107 | files = ( 108 | 6B48C179258D7DFA00E8BB9C /* NanoFrame.h in Headers */, 109 | ); 110 | runOnlyForDeploymentPostprocessing = 0; 111 | }; 112 | /* End PBXHeadersBuildPhase section */ 113 | 114 | /* Begin PBXNativeTarget section */ 115 | 6B48C167258D7DF900E8BB9C /* NanoFrame */ = { 116 | isa = PBXNativeTarget; 117 | buildConfigurationList = 6B48C17C258D7DFA00E8BB9C /* Build configuration list for PBXNativeTarget "NanoFrame" */; 118 | buildPhases = ( 119 | 6B48C163258D7DF900E8BB9C /* Headers */, 120 | 6B48C164258D7DF900E8BB9C /* Sources */, 121 | 6B48C165258D7DF900E8BB9C /* Frameworks */, 122 | 6B48C166258D7DF900E8BB9C /* Resources */, 123 | ); 124 | buildRules = ( 125 | ); 126 | dependencies = ( 127 | ); 128 | name = NanoFrame; 129 | productName = NanoFrame; 130 | productReference = 6B48C168258D7DF900E8BB9C /* NanoFrame.framework */; 131 | productType = "com.apple.product-type.framework"; 132 | }; 133 | 6B48C170258D7DFA00E8BB9C /* NanoFrameTests */ = { 134 | isa = PBXNativeTarget; 135 | buildConfigurationList = 6B48C17F258D7DFA00E8BB9C /* Build configuration list for PBXNativeTarget "NanoFrameTests" */; 136 | buildPhases = ( 137 | 6B48C16D258D7DFA00E8BB9C /* Sources */, 138 | 6B48C16E258D7DFA00E8BB9C /* Frameworks */, 139 | 6B48C16F258D7DFA00E8BB9C /* Resources */, 140 | ); 141 | buildRules = ( 142 | ); 143 | dependencies = ( 144 | 6B48C174258D7DFA00E8BB9C /* PBXTargetDependency */, 145 | ); 146 | name = NanoFrameTests; 147 | productName = NanoFrameTests; 148 | productReference = 6B48C171258D7DFA00E8BB9C /* NanoFrameTests.xctest */; 149 | productType = "com.apple.product-type.bundle.unit-test"; 150 | }; 151 | /* End PBXNativeTarget section */ 152 | 153 | /* Begin PBXProject section */ 154 | 6B48C15F258D7DF900E8BB9C /* Project object */ = { 155 | isa = PBXProject; 156 | attributes = { 157 | LastSwiftUpdateCheck = 1230; 158 | LastUpgradeCheck = 1230; 159 | TargetAttributes = { 160 | 6B48C167258D7DF900E8BB9C = { 161 | CreatedOnToolsVersion = 12.3; 162 | }; 163 | 6B48C170258D7DFA00E8BB9C = { 164 | CreatedOnToolsVersion = 12.3; 165 | }; 166 | }; 167 | }; 168 | buildConfigurationList = 6B48C162258D7DF900E8BB9C /* Build configuration list for PBXProject "NanoFrame" */; 169 | compatibilityVersion = "Xcode 9.3"; 170 | developmentRegion = en; 171 | hasScannedForEncodings = 0; 172 | knownRegions = ( 173 | en, 174 | Base, 175 | ); 176 | mainGroup = 6B48C15E258D7DF900E8BB9C; 177 | productRefGroup = 6B48C169258D7DF900E8BB9C /* Products */; 178 | projectDirPath = ""; 179 | projectRoot = ""; 180 | targets = ( 181 | 6B48C167258D7DF900E8BB9C /* NanoFrame */, 182 | 6B48C170258D7DFA00E8BB9C /* NanoFrameTests */, 183 | ); 184 | }; 185 | /* End PBXProject section */ 186 | 187 | /* Begin PBXResourcesBuildPhase section */ 188 | 6B48C166258D7DF900E8BB9C /* Resources */ = { 189 | isa = PBXResourcesBuildPhase; 190 | buildActionMask = 2147483647; 191 | files = ( 192 | ); 193 | runOnlyForDeploymentPostprocessing = 0; 194 | }; 195 | 6B48C16F258D7DFA00E8BB9C /* Resources */ = { 196 | isa = PBXResourcesBuildPhase; 197 | buildActionMask = 2147483647; 198 | files = ( 199 | ); 200 | runOnlyForDeploymentPostprocessing = 0; 201 | }; 202 | /* End PBXResourcesBuildPhase section */ 203 | 204 | /* Begin PBXSourcesBuildPhase section */ 205 | 6B48C164258D7DF900E8BB9C /* Sources */ = { 206 | isa = PBXSourcesBuildPhase; 207 | buildActionMask = 2147483647; 208 | files = ( 209 | BA79833368388840ACBE6904 /* UIColor+NanoFrame.swift in Sources */, 210 | BA79842FA052048F7A7E12B3 /* CALayer+NanoFrame.swift in Sources */, 211 | BA798C4C8491E166D9782703 /* UIImage+NanoFrame.swift in Sources */, 212 | BA798832A5D7BC8C4604A9FA /* UIView+NanoFrame.swift in Sources */, 213 | ); 214 | runOnlyForDeploymentPostprocessing = 0; 215 | }; 216 | 6B48C16D258D7DFA00E8BB9C /* Sources */ = { 217 | isa = PBXSourcesBuildPhase; 218 | buildActionMask = 2147483647; 219 | files = ( 220 | 6B48C177258D7DFA00E8BB9C /* NanoFrameTests.swift in Sources */, 221 | ); 222 | runOnlyForDeploymentPostprocessing = 0; 223 | }; 224 | /* End PBXSourcesBuildPhase section */ 225 | 226 | /* Begin PBXTargetDependency section */ 227 | 6B48C174258D7DFA00E8BB9C /* PBXTargetDependency */ = { 228 | isa = PBXTargetDependency; 229 | target = 6B48C167258D7DF900E8BB9C /* NanoFrame */; 230 | targetProxy = 6B48C173258D7DFA00E8BB9C /* PBXContainerItemProxy */; 231 | }; 232 | /* End PBXTargetDependency section */ 233 | 234 | /* Begin XCBuildConfiguration section */ 235 | 6B48C17A258D7DFA00E8BB9C /* Debug */ = { 236 | isa = XCBuildConfiguration; 237 | buildSettings = { 238 | ALWAYS_SEARCH_USER_PATHS = NO; 239 | CLANG_ANALYZER_NONNULL = YES; 240 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 241 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 242 | CLANG_CXX_LIBRARY = "libc++"; 243 | CLANG_ENABLE_MODULES = YES; 244 | CLANG_ENABLE_OBJC_ARC = YES; 245 | CLANG_ENABLE_OBJC_WEAK = YES; 246 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 247 | CLANG_WARN_BOOL_CONVERSION = YES; 248 | CLANG_WARN_COMMA = YES; 249 | CLANG_WARN_CONSTANT_CONVERSION = YES; 250 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 251 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 252 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 253 | CLANG_WARN_EMPTY_BODY = YES; 254 | CLANG_WARN_ENUM_CONVERSION = YES; 255 | CLANG_WARN_INFINITE_RECURSION = YES; 256 | CLANG_WARN_INT_CONVERSION = YES; 257 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 258 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 259 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 260 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 261 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 262 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 263 | CLANG_WARN_STRICT_PROTOTYPES = YES; 264 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 265 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 266 | CLANG_WARN_UNREACHABLE_CODE = YES; 267 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 268 | COPY_PHASE_STRIP = NO; 269 | CURRENT_PROJECT_VERSION = 1; 270 | DEBUG_INFORMATION_FORMAT = dwarf; 271 | ENABLE_STRICT_OBJC_MSGSEND = YES; 272 | ENABLE_TESTABILITY = YES; 273 | GCC_C_LANGUAGE_STANDARD = gnu11; 274 | GCC_DYNAMIC_NO_PIC = NO; 275 | GCC_NO_COMMON_BLOCKS = YES; 276 | GCC_OPTIMIZATION_LEVEL = 0; 277 | GCC_PREPROCESSOR_DEFINITIONS = ( 278 | "DEBUG=1", 279 | "$(inherited)", 280 | ); 281 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 282 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 283 | GCC_WARN_UNDECLARED_SELECTOR = YES; 284 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 285 | GCC_WARN_UNUSED_FUNCTION = YES; 286 | GCC_WARN_UNUSED_VARIABLE = YES; 287 | IPHONEOS_DEPLOYMENT_TARGET = 14.3; 288 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 289 | MTL_FAST_MATH = YES; 290 | ONLY_ACTIVE_ARCH = YES; 291 | SDKROOT = iphoneos; 292 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 293 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 294 | VERSIONING_SYSTEM = "apple-generic"; 295 | VERSION_INFO_PREFIX = ""; 296 | }; 297 | name = Debug; 298 | }; 299 | 6B48C17B258D7DFA00E8BB9C /* Release */ = { 300 | isa = XCBuildConfiguration; 301 | buildSettings = { 302 | ALWAYS_SEARCH_USER_PATHS = NO; 303 | CLANG_ANALYZER_NONNULL = YES; 304 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 305 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 306 | CLANG_CXX_LIBRARY = "libc++"; 307 | CLANG_ENABLE_MODULES = YES; 308 | CLANG_ENABLE_OBJC_ARC = YES; 309 | CLANG_ENABLE_OBJC_WEAK = YES; 310 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 311 | CLANG_WARN_BOOL_CONVERSION = YES; 312 | CLANG_WARN_COMMA = YES; 313 | CLANG_WARN_CONSTANT_CONVERSION = YES; 314 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 315 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 316 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 317 | CLANG_WARN_EMPTY_BODY = YES; 318 | CLANG_WARN_ENUM_CONVERSION = YES; 319 | CLANG_WARN_INFINITE_RECURSION = YES; 320 | CLANG_WARN_INT_CONVERSION = YES; 321 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 322 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 323 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 324 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 325 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 326 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 327 | CLANG_WARN_STRICT_PROTOTYPES = YES; 328 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 329 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 330 | CLANG_WARN_UNREACHABLE_CODE = YES; 331 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 332 | COPY_PHASE_STRIP = NO; 333 | CURRENT_PROJECT_VERSION = 1; 334 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 335 | ENABLE_NS_ASSERTIONS = NO; 336 | ENABLE_STRICT_OBJC_MSGSEND = YES; 337 | GCC_C_LANGUAGE_STANDARD = gnu11; 338 | GCC_NO_COMMON_BLOCKS = YES; 339 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 340 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 341 | GCC_WARN_UNDECLARED_SELECTOR = YES; 342 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 343 | GCC_WARN_UNUSED_FUNCTION = YES; 344 | GCC_WARN_UNUSED_VARIABLE = YES; 345 | IPHONEOS_DEPLOYMENT_TARGET = 14.3; 346 | MTL_ENABLE_DEBUG_INFO = NO; 347 | MTL_FAST_MATH = YES; 348 | SDKROOT = iphoneos; 349 | SWIFT_COMPILATION_MODE = wholemodule; 350 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 351 | VALIDATE_PRODUCT = YES; 352 | VERSIONING_SYSTEM = "apple-generic"; 353 | VERSION_INFO_PREFIX = ""; 354 | }; 355 | name = Release; 356 | }; 357 | 6B48C17D258D7DFA00E8BB9C /* Debug */ = { 358 | isa = XCBuildConfiguration; 359 | buildSettings = { 360 | CODE_SIGN_STYLE = Automatic; 361 | DEFINES_MODULE = YES; 362 | DEVELOPMENT_TEAM = VJ57RGVK27; 363 | DYLIB_COMPATIBILITY_VERSION = 1; 364 | DYLIB_CURRENT_VERSION = 1; 365 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 366 | INFOPLIST_FILE = NanoFrame/Info.plist; 367 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 368 | LD_RUNPATH_SEARCH_PATHS = ( 369 | "$(inherited)", 370 | "@executable_path/Frameworks", 371 | "@loader_path/Frameworks", 372 | ); 373 | PRODUCT_BUNDLE_IDENTIFIER = appsquickly.NanoFrame; 374 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 375 | SKIP_INSTALL = YES; 376 | SWIFT_VERSION = 5.0; 377 | TARGETED_DEVICE_FAMILY = "1,2"; 378 | }; 379 | name = Debug; 380 | }; 381 | 6B48C17E258D7DFA00E8BB9C /* Release */ = { 382 | isa = XCBuildConfiguration; 383 | buildSettings = { 384 | CODE_SIGN_STYLE = Automatic; 385 | DEFINES_MODULE = YES; 386 | DEVELOPMENT_TEAM = VJ57RGVK27; 387 | DYLIB_COMPATIBILITY_VERSION = 1; 388 | DYLIB_CURRENT_VERSION = 1; 389 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 390 | INFOPLIST_FILE = NanoFrame/Info.plist; 391 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 392 | LD_RUNPATH_SEARCH_PATHS = ( 393 | "$(inherited)", 394 | "@executable_path/Frameworks", 395 | "@loader_path/Frameworks", 396 | ); 397 | PRODUCT_BUNDLE_IDENTIFIER = appsquickly.NanoFrame; 398 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 399 | SKIP_INSTALL = YES; 400 | SWIFT_VERSION = 5.0; 401 | TARGETED_DEVICE_FAMILY = "1,2"; 402 | }; 403 | name = Release; 404 | }; 405 | 6B48C180258D7DFA00E8BB9C /* Debug */ = { 406 | isa = XCBuildConfiguration; 407 | buildSettings = { 408 | CODE_SIGN_STYLE = Automatic; 409 | DEVELOPMENT_TEAM = VJ57RGVK27; 410 | INFOPLIST_FILE = NanoFrameTests/Info.plist; 411 | LD_RUNPATH_SEARCH_PATHS = ( 412 | "$(inherited)", 413 | "@executable_path/Frameworks", 414 | "@loader_path/Frameworks", 415 | ); 416 | PRODUCT_BUNDLE_IDENTIFIER = appsquickly.NanoFrameTests; 417 | PRODUCT_NAME = "$(TARGET_NAME)"; 418 | SWIFT_VERSION = 5.0; 419 | TARGETED_DEVICE_FAMILY = "1,2"; 420 | }; 421 | name = Debug; 422 | }; 423 | 6B48C181258D7DFA00E8BB9C /* Release */ = { 424 | isa = XCBuildConfiguration; 425 | buildSettings = { 426 | CODE_SIGN_STYLE = Automatic; 427 | DEVELOPMENT_TEAM = VJ57RGVK27; 428 | INFOPLIST_FILE = NanoFrameTests/Info.plist; 429 | LD_RUNPATH_SEARCH_PATHS = ( 430 | "$(inherited)", 431 | "@executable_path/Frameworks", 432 | "@loader_path/Frameworks", 433 | ); 434 | PRODUCT_BUNDLE_IDENTIFIER = appsquickly.NanoFrameTests; 435 | PRODUCT_NAME = "$(TARGET_NAME)"; 436 | SWIFT_VERSION = 5.0; 437 | TARGETED_DEVICE_FAMILY = "1,2"; 438 | }; 439 | name = Release; 440 | }; 441 | /* End XCBuildConfiguration section */ 442 | 443 | /* Begin XCConfigurationList section */ 444 | 6B48C162258D7DF900E8BB9C /* Build configuration list for PBXProject "NanoFrame" */ = { 445 | isa = XCConfigurationList; 446 | buildConfigurations = ( 447 | 6B48C17A258D7DFA00E8BB9C /* Debug */, 448 | 6B48C17B258D7DFA00E8BB9C /* Release */, 449 | ); 450 | defaultConfigurationIsVisible = 0; 451 | defaultConfigurationName = Release; 452 | }; 453 | 6B48C17C258D7DFA00E8BB9C /* Build configuration list for PBXNativeTarget "NanoFrame" */ = { 454 | isa = XCConfigurationList; 455 | buildConfigurations = ( 456 | 6B48C17D258D7DFA00E8BB9C /* Debug */, 457 | 6B48C17E258D7DFA00E8BB9C /* Release */, 458 | ); 459 | defaultConfigurationIsVisible = 0; 460 | defaultConfigurationName = Release; 461 | }; 462 | 6B48C17F258D7DFA00E8BB9C /* Build configuration list for PBXNativeTarget "NanoFrameTests" */ = { 463 | isa = XCConfigurationList; 464 | buildConfigurations = ( 465 | 6B48C180258D7DFA00E8BB9C /* Debug */, 466 | 6B48C181258D7DFA00E8BB9C /* Release */, 467 | ); 468 | defaultConfigurationIsVisible = 0; 469 | defaultConfigurationName = Release; 470 | }; 471 | /* End XCConfigurationList section */ 472 | }; 473 | rootObject = 6B48C15F258D7DF900E8BB9C /* Project object */; 474 | } 475 | -------------------------------------------------------------------------------- /NanoFrame.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /NanoFrame.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /NanoFrame/CALayer+NanoFrame.swift: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AppsQuick.ly 4 | // Copyright 2015 - 2020 AppsQuick.ly 5 | // All Rights Reserved. 6 | // 7 | // NOTICE: Use is subject to license terms. 8 | // 9 | //////////////////////////////////////////////////////////////////////////////// 10 | 11 | import Foundation 12 | import UIKit 13 | 14 | public extension CALayer { 15 | 16 | class func with(image: UIImage) -> CALayer { 17 | let layer = CALayer() 18 | layer.frame = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height) 19 | layer.contents = image.cgImage 20 | return layer 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /NanoFrame/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | 22 | 23 | -------------------------------------------------------------------------------- /NanoFrame/NanoFrame.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AppsQuick.ly 4 | // Copyright 2015 - 2020 AppsQuick.ly 5 | // All Rights Reserved. 6 | // 7 | // NOTICE: Use is subject to license terms. 8 | // 9 | //////////////////////////////////////////////////////////////////////////////// 10 | 11 | #import 12 | 13 | //! Project version number for NanoFrame. 14 | FOUNDATION_EXPORT double NanoFrameVersionNumber; 15 | 16 | //! Project version string for NanoFrame. 17 | FOUNDATION_EXPORT const unsigned char NanoFrameVersionString[]; 18 | 19 | // In this header, you should import all the public headers of your framework using statements like #import 20 | 21 | -------------------------------------------------------------------------------- /NanoFrame/UIColor+NanoFrame.swift: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AppsQuick.ly 4 | // Copyright 2015 - 2020 AppsQuick.ly 5 | // All Rights Reserved. 6 | // 7 | // NOTICE: Use is subject to license terms. 8 | // 9 | //////////////////////////////////////////////////////////////////////////////// 10 | 11 | 12 | import Foundation 13 | import UIKit 14 | 15 | public enum GradientDirection { 16 | case TopToBottom 17 | case LeftToRight 18 | } 19 | 20 | public extension UIColor { 21 | 22 | convenience init(hex: Int) { 23 | self.init(hex: hex, alpha: 1) 24 | } 25 | 26 | convenience init(hex: Int, alpha: CGFloat) { 27 | let components = ( 28 | R: CGFloat((hex >> 16) & 0xff) / 255, 29 | G: CGFloat((hex >> 08) & 0xff) / 255, 30 | B: CGFloat((hex >> 00) & 0xff) / 255 31 | ) 32 | self.init(red: components.R, green: components.G, blue: components.B, alpha: alpha) 33 | } 34 | 35 | convenience init(gradient: [UIColor], direction: GradientDirection = .TopToBottom, inFrame: CGRect) { 36 | 37 | guard gradient.count >= 2 else { 38 | fatalError("Gradient is useless without at least two colors") 39 | } 40 | 41 | if inFrame.size.height == 0 || inFrame.size.width == 0 { 42 | self.init(hex: 0x000000) 43 | } else { 44 | let gradientLayer = CAGradientLayer() 45 | gradientLayer.frame = inFrame 46 | gradientLayer.colors = gradient.map({ $0.cgColor }) 47 | 48 | if direction == .LeftToRight { 49 | gradientLayer.startPoint = CGPoint(x: 0.0, y: 0.5) 50 | gradientLayer.endPoint = CGPoint(x: 1.0, y: 0.5) 51 | } 52 | 53 | UIGraphicsBeginImageContext(gradientLayer.bounds.size) 54 | gradientLayer.render(in: UIGraphicsGetCurrentContext()!) 55 | let image = UIGraphicsGetImageFromCurrentImageContext() 56 | UIGraphicsEndImageContext() 57 | 58 | self.init(patternImage: image!) 59 | } 60 | } 61 | 62 | 63 | convenience init(topToBottom: [UIColor], inFrame: CGRect) { 64 | self.init(gradient: topToBottom, direction: .TopToBottom, inFrame: inFrame) 65 | } 66 | 67 | convenience init(leftToRight: [UIColor], inFrame: CGRect) { 68 | self.init(gradient: leftToRight, direction: .LeftToRight, inFrame: inFrame) 69 | } 70 | 71 | } -------------------------------------------------------------------------------- /NanoFrame/UIImage+NanoFrame.swift: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AppsQuick.ly 4 | // Copyright 2015 - 2020 AppsQuick.ly 5 | // All Rights Reserved. 6 | // 7 | // NOTICE: Use is subject to license terms. 8 | // 9 | //////////////////////////////////////////////////////////////////////////////// 10 | 11 | 12 | import Foundation 13 | import UIKit 14 | 15 | public extension UIImage { 16 | 17 | class func imageWith(view: UIView) -> UIImage { 18 | imageWith(layer: view.layer) 19 | } 20 | 21 | class func imageWith(layer: CALayer) -> UIImage { 22 | UIGraphicsBeginImageContextWithOptions(layer.frame.size, false, UIScreen.main.scale) 23 | 24 | if let context = UIGraphicsGetCurrentContext() { 25 | layer.render(in: context) 26 | } 27 | let out = UIGraphicsGetImageFromCurrentImageContext() 28 | 29 | UIGraphicsEndImageContext() 30 | return out! 31 | } 32 | 33 | func tint(_ color: UIColor) -> UIImage { 34 | UIGraphicsBeginImageContextWithOptions(size, false, 0.0) 35 | let bounds = CGRect(x: 0, y: 0, width: size.width, height: size.height) 36 | 37 | color.setFill() 38 | 39 | UIRectFill(bounds) 40 | draw(in: bounds, blendMode: .destinationIn, alpha: 1.0) 41 | 42 | let image = UIGraphicsGetImageFromCurrentImageContext() 43 | UIGraphicsEndImageContext() 44 | 45 | return image! 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /NanoFrame/UIView+NanoFrame.swift: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AppsQuick.ly 4 | // Copyright 2015 - 2020 AppsQuick.ly 5 | // All Rights Reserved. 6 | // 7 | // NOTICE: Use is subject to license terms. 8 | // 9 | //////////////////////////////////////////////////////////////////////////////// 10 | 11 | 12 | import Foundation 13 | import UIKit 14 | 15 | public extension UIView { 16 | 17 | var position: CGPoint { 18 | get { 19 | frame.origin 20 | } 21 | set (value) { 22 | center = CGPoint(x: value.x + bounds.size.width / 2.0, y: value.y + bounds.size.height / 2.0) 23 | } 24 | } 25 | 26 | var x: CGFloat { 27 | get { 28 | frame.origin.x 29 | } 30 | set (value) { 31 | frame = CGRect(x: value, y: y, width: bounds.size.width, height: bounds.size.height) 32 | } 33 | } 34 | 35 | var y: CGFloat { 36 | get { 37 | frame.origin.y; 38 | } 39 | set (value) { 40 | frame = CGRect(x: x, y: value, width: self.bounds.size.width, height: self.bounds.size.height) 41 | } 42 | } 43 | 44 | var right: CGFloat { 45 | get { 46 | frame.maxX; 47 | } 48 | set (newValue) { 49 | center = CGPoint(x: newValue - bounds.size.width / 2.0, y: center.y) 50 | } 51 | } 52 | 53 | var bottom: CGFloat { 54 | get { 55 | frame.maxY; 56 | } 57 | set (newValue) { 58 | center = CGPoint(x: center.x, y: newValue - bounds.size.height / 2.0) 59 | } 60 | } 61 | 62 | var size: CGSize { 63 | get { 64 | bounds.size 65 | } 66 | set (value) { 67 | bounds.size = value; 68 | } 69 | 70 | } 71 | 72 | var width: CGFloat { 73 | get { 74 | bounds.size.width 75 | } 76 | set (value) { 77 | bounds.size.width = value 78 | } 79 | } 80 | 81 | var height: CGFloat { 82 | get { 83 | bounds.size.height 84 | } 85 | set (value) { 86 | bounds.size.height = value 87 | } 88 | } 89 | 90 | func center(in rect: CGRect) { 91 | centerHorizontally(in: rect) 92 | centerVertically(in: rect) 93 | } 94 | 95 | func centerVertically(in rect: CGRect) { 96 | y = rect.origin.y + (rect.size.height - bounds.size.height) / 2.0; 97 | } 98 | 99 | func centerHorizontally(in rect: CGRect) { 100 | x = rect.origin.x + (rect.size.width - bounds.size.width) / 2.0; 101 | } 102 | 103 | func centerInSuperView() { 104 | guard superview != nil else { return } 105 | center = CGPoint(x: superview!.bounds.size.width / 2.0, y: superview!.bounds.size.height / 2.0) 106 | } 107 | 108 | func centerVerticallyInSuperView() { 109 | guard superview != nil else { return } 110 | y = (superview!.bounds.size.height - bounds.size.height) / 2.0; 111 | } 112 | 113 | func centerHorizontallyInSuperView() { 114 | guard superview != nil else { return } 115 | x = (superview!.bounds.size.width - bounds.size.width) / 2.0; 116 | } 117 | 118 | func centerHorizontally(below view: UIView, padding: CGFloat = 0.0) { 119 | y = view.frame.maxY + padding; 120 | x = view.x + (view.bounds.size.width - bounds.size.width) / 2.0; 121 | } 122 | 123 | func alignLeftHorizontally(below view: UIView, padding: CGFloat = 0.0) { 124 | y = view.frame.maxY + padding; 125 | x = view.x; 126 | } 127 | 128 | func alignRightHorizontally(below view: UIView, padding: CGFloat = 0.0) { 129 | y = view.frame.maxY + padding; 130 | right = view.right; 131 | } 132 | 133 | } -------------------------------------------------------------------------------- /NanoFrameTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /NanoFrameTests/NanoFrameTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NanoFrameTests.swift 3 | // NanoFrameTests 4 | // 5 | // Created by Jasper Blues on 12/19/20. 6 | // 7 | 8 | import XCTest 9 | @testable import NanoFrame 10 | 11 | class NanoFrameTests: XCTestCase { 12 | 13 | override func setUpWithError() throws { 14 | // Put setup code here. This method is called before the invocation of each test method in the class. 15 | } 16 | 17 | override func tearDownWithError() throws { 18 | // Put teardown code here. This method is called after the invocation of each test method in the class. 19 | } 20 | 21 | func testExample() throws { 22 | // This is an example of a functional test case. 23 | // Use XCTAssert and related functions to verify your tests produce the correct results. 24 | } 25 | 26 | func testPerformanceExample() throws { 27 | // This is an example of a performance test case. 28 | self.measure { 29 | // Put the code you want to measure the time of here. 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NanoFrame 2 | 3 | Getting back to basics with minimal frame-based layout and UIKit utils. (aka auto-layout without using auto-layout). 4 | 5 | ----- 6 | 7 | ## Why? 8 | 9 | "Everything should be made as simple as possible, but no simpler". This quote, attributed to Albert Einstein doesn't just apply to solving the deepest mysteries in science. We can use it as a guide-post in software development too. In fact "simplicity" among "communication", "feedback", "courage" and "respect" is one of the five core values of [Extreme Programming](https://en.wikipedia.org/wiki/Extreme_programming). 10 | 11 | ## Why not Autolayout? 12 | 13 | We can use it, however it pays to understand the basics first! 14 | 15 | Before there was auto-layout, there were simpler days, with frame-based layout. Autolayout came along to address the issue of laying out views relative to one another, according to various screen sizes. However it is possible (and pretty easy) to lay out views relative to one another, using frame based layouts. We need to understand two fundamental principles; 16 | 17 | * A `UIView`'s bounds is the `CGRect` frame, in its _own_ coordinate space. The origin `CGPoint` (0,0) is in the top left corner. 18 | * A `UIView`'s frame is the CGRect _relative_ to its superview. We can place a `UIView` at some coordinates (100, 50) in some other UIView's frame. 19 | 20 | :warning: _When a view is the root view, its frame and bounds are the same_. 21 | 22 | Note the word relative above. We can now lay out views relative to one another using frame and bounds. But just working at a `CGRect` level of abstraction becomes verbose and requires a lot of tedious arithmetic. Computers love tedious arithmetic, so let's add some extension functions to `UIView` for commmon operations. Now we can lay out views as follows: 23 | 24 | ```swift 25 | override func layoutSubviews() { 26 | super.layoutSubviews() 27 | 28 | contentView.frame = bounds 29 | glowView.frame = contentView.bounds.insetBy(dx: 10, dy: 6) 30 | 31 | let backgroundColors = [UIColor(hex: 0x424243), UIColor(hex: 0x212121)] 32 | glowView.backgroundColor = UIColor(topToBottom: backgroundColors, inFrame: glowView.frame) 33 | glowView.layer.shadowPath = UIBezierPath(rect: glowView.bounds).cgPath 34 | 35 | titleLabel.width = glowView.width - 30 36 | titleLabel.centerVerticallyInSuperView() 37 | titleLabel.x = glowView.x + 10 38 | 39 | starButton.centerVerticallyInSuperView() 40 | starButton.right = glowView.right - 20 41 | } 42 | ``` 43 | 44 | In the example above we're laying out the `titleLabel` and `starButton` _relative_ to the superview, just as we do with auto-layout. In fact if we renamed the `x` and `right` computed properties to `leading` and `trailing` it would look even more like auto-layout. 45 | 46 | The difference is that we must do this in the `layoutSubviews()` function (with autolayout we can declare constraints anywhere) however we might consider this a feature. Now we know where to look for layout related code. 47 | 48 | ## Composition 49 | 50 | There is a reason we come across the word 'compositing' a lot when it comes to graphics. This pattern works well for rendering - start with a root node, and branch out. It can be paralleled. So rather than a complex ancestral heirarchy (`DogView` extends `AnimalView` .... extends `UIView`) we compose complex views from simple pieces. 51 | 52 | :warning: _In fact, we can use [composition over inheritance](https://en.wikipedia.org/wiki/Composition_over_inheritance) as a general rule of thumb._ 53 | 54 | The approach above works well for composition of views. If you see a long `layoutSubviews()` function, there's some evidence that extracting a reusable subview will promote reusablility. Now you can layout this child view relative to the parent. And it becomes simple to reaon about. 55 | 56 | Your top-level view's model can deal at the application _domain's_ model, so if for example you have a top-level weather report view, you can feed that view a weather report model. 57 | 58 | ![Composition Example](https://raw.githubusercontent.com/appsquickly/NanoFrame/master/composite.png) 59 | 60 | ## Animation 61 | 62 | Now that we know how to layout views relative ot one another with composition, we can animate them too. 63 | 64 | ```swift 65 | CATransaction.flush() 66 | UIView.animate(withDuration: 0.28, delay: 0, options: [.curveEaseIn], animations: { [self] in 67 | titleLabel.x = starButton.x - 30 68 | }) 69 | ``` 70 | 71 | We use a built-in animation curve above. However we could easily apply functions from Newtonian physics to approximate gravity, friction and so forth. 72 | -------------------------------------------------------------------------------- /composite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appsquickly/NanoFrame/1914c2f0173fb777d1e632c864d9006a0bfebae6/composite.png --------------------------------------------------------------------------------