├── .gitignore ├── LICENSE ├── README.md ├── ScreenShots ├── 1.png └── 2.png └── ShapedImageView ├── ShapedImageView.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── ShapedImageView ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── HJShapedImageView.h ├── HJShapedImageView.m ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Images │ ├── gray_bubble_right@2x.png │ └── scenery.jpg ├── Info.plist ├── ViewController.h ├── ViewController.m └── main.m └── ShapedImageViewTests ├── Info.plist └── ShapedImageViewTests.m /.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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ShapedImageView 2 | =============== 3 | 4 | -------------------------------------------------------------------------------- /ScreenShots/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heavensword/ShapedImageView/3e3a7e9655f923005ec2ce8cae185acb230b0f14/ScreenShots/1.png -------------------------------------------------------------------------------- /ScreenShots/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heavensword/ShapedImageView/3e3a7e9655f923005ec2ce8cae185acb230b0f14/ScreenShots/2.png -------------------------------------------------------------------------------- /ShapedImageView/ShapedImageView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 5055DC381A18B04D00024066 /* HJShapedImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 5055DC371A18B04D00024066 /* HJShapedImageView.m */; }; 11 | 5055DC3C1A18BEA500024066 /* gray_bubble_right@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 5055DC3A1A18BEA500024066 /* gray_bubble_right@2x.png */; }; 12 | 5055DC3D1A18BEA500024066 /* scenery.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 5055DC3B1A18BEA500024066 /* scenery.jpg */; }; 13 | 50B248B81A17A97300B9D12C /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 50B248B71A17A97300B9D12C /* main.m */; }; 14 | 50B248BB1A17A97300B9D12C /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 50B248BA1A17A97300B9D12C /* AppDelegate.m */; }; 15 | 50B248BE1A17A97300B9D12C /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 50B248BD1A17A97300B9D12C /* ViewController.m */; }; 16 | 50B248C11A17A97300B9D12C /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 50B248BF1A17A97300B9D12C /* Main.storyboard */; }; 17 | 50B248C31A17A97300B9D12C /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 50B248C21A17A97300B9D12C /* Images.xcassets */; }; 18 | 50B248C61A17A97300B9D12C /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50B248C41A17A97300B9D12C /* LaunchScreen.xib */; }; 19 | 50B248D21A17A97300B9D12C /* ShapedImageViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 50B248D11A17A97300B9D12C /* ShapedImageViewTests.m */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXContainerItemProxy section */ 23 | 50B248CC1A17A97300B9D12C /* PBXContainerItemProxy */ = { 24 | isa = PBXContainerItemProxy; 25 | containerPortal = 50B248AA1A17A97300B9D12C /* Project object */; 26 | proxyType = 1; 27 | remoteGlobalIDString = 50B248B11A17A97300B9D12C; 28 | remoteInfo = ShapedImageView; 29 | }; 30 | /* End PBXContainerItemProxy section */ 31 | 32 | /* Begin PBXFileReference section */ 33 | 5055DC361A18B04D00024066 /* HJShapedImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HJShapedImageView.h; sourceTree = ""; }; 34 | 5055DC371A18B04D00024066 /* HJShapedImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HJShapedImageView.m; sourceTree = ""; }; 35 | 5055DC3A1A18BEA500024066 /* gray_bubble_right@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "gray_bubble_right@2x.png"; sourceTree = ""; }; 36 | 5055DC3B1A18BEA500024066 /* scenery.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = scenery.jpg; sourceTree = ""; }; 37 | 50B248B21A17A97300B9D12C /* ShapedImageView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ShapedImageView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 38 | 50B248B61A17A97300B9D12C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 39 | 50B248B71A17A97300B9D12C /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 40 | 50B248B91A17A97300B9D12C /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 41 | 50B248BA1A17A97300B9D12C /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 42 | 50B248BC1A17A97300B9D12C /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 43 | 50B248BD1A17A97300B9D12C /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 44 | 50B248C01A17A97300B9D12C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 45 | 50B248C21A17A97300B9D12C /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 46 | 50B248C51A17A97300B9D12C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 47 | 50B248CB1A17A97300B9D12C /* ShapedImageViewTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ShapedImageViewTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 48 | 50B248D01A17A97300B9D12C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 49 | 50B248D11A17A97300B9D12C /* ShapedImageViewTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ShapedImageViewTests.m; sourceTree = ""; }; 50 | /* End PBXFileReference section */ 51 | 52 | /* Begin PBXFrameworksBuildPhase section */ 53 | 50B248AF1A17A97300B9D12C /* Frameworks */ = { 54 | isa = PBXFrameworksBuildPhase; 55 | buildActionMask = 2147483647; 56 | files = ( 57 | ); 58 | runOnlyForDeploymentPostprocessing = 0; 59 | }; 60 | 50B248C81A17A97300B9D12C /* Frameworks */ = { 61 | isa = PBXFrameworksBuildPhase; 62 | buildActionMask = 2147483647; 63 | files = ( 64 | ); 65 | runOnlyForDeploymentPostprocessing = 0; 66 | }; 67 | /* End PBXFrameworksBuildPhase section */ 68 | 69 | /* Begin PBXGroup section */ 70 | 5055DC391A18BEA500024066 /* Images */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | 5055DC3A1A18BEA500024066 /* gray_bubble_right@2x.png */, 74 | 5055DC3B1A18BEA500024066 /* scenery.jpg */, 75 | ); 76 | path = Images; 77 | sourceTree = ""; 78 | }; 79 | 50B248A91A17A97300B9D12C = { 80 | isa = PBXGroup; 81 | children = ( 82 | 50B248B41A17A97300B9D12C /* ShapedImageView */, 83 | 50B248CE1A17A97300B9D12C /* ShapedImageViewTests */, 84 | 50B248B31A17A97300B9D12C /* Products */, 85 | ); 86 | sourceTree = ""; 87 | }; 88 | 50B248B31A17A97300B9D12C /* Products */ = { 89 | isa = PBXGroup; 90 | children = ( 91 | 50B248B21A17A97300B9D12C /* ShapedImageView.app */, 92 | 50B248CB1A17A97300B9D12C /* ShapedImageViewTests.xctest */, 93 | ); 94 | name = Products; 95 | sourceTree = ""; 96 | }; 97 | 50B248B41A17A97300B9D12C /* ShapedImageView */ = { 98 | isa = PBXGroup; 99 | children = ( 100 | 5055DC391A18BEA500024066 /* Images */, 101 | 50B248B91A17A97300B9D12C /* AppDelegate.h */, 102 | 50B248BA1A17A97300B9D12C /* AppDelegate.m */, 103 | 50B248BC1A17A97300B9D12C /* ViewController.h */, 104 | 50B248BD1A17A97300B9D12C /* ViewController.m */, 105 | 50B248BF1A17A97300B9D12C /* Main.storyboard */, 106 | 50B248C21A17A97300B9D12C /* Images.xcassets */, 107 | 50B248C41A17A97300B9D12C /* LaunchScreen.xib */, 108 | 50B248B51A17A97300B9D12C /* Supporting Files */, 109 | 5055DC361A18B04D00024066 /* HJShapedImageView.h */, 110 | 5055DC371A18B04D00024066 /* HJShapedImageView.m */, 111 | ); 112 | path = ShapedImageView; 113 | sourceTree = ""; 114 | }; 115 | 50B248B51A17A97300B9D12C /* Supporting Files */ = { 116 | isa = PBXGroup; 117 | children = ( 118 | 50B248B61A17A97300B9D12C /* Info.plist */, 119 | 50B248B71A17A97300B9D12C /* main.m */, 120 | ); 121 | name = "Supporting Files"; 122 | sourceTree = ""; 123 | }; 124 | 50B248CE1A17A97300B9D12C /* ShapedImageViewTests */ = { 125 | isa = PBXGroup; 126 | children = ( 127 | 50B248D11A17A97300B9D12C /* ShapedImageViewTests.m */, 128 | 50B248CF1A17A97300B9D12C /* Supporting Files */, 129 | ); 130 | path = ShapedImageViewTests; 131 | sourceTree = ""; 132 | }; 133 | 50B248CF1A17A97300B9D12C /* Supporting Files */ = { 134 | isa = PBXGroup; 135 | children = ( 136 | 50B248D01A17A97300B9D12C /* Info.plist */, 137 | ); 138 | name = "Supporting Files"; 139 | sourceTree = ""; 140 | }; 141 | /* End PBXGroup section */ 142 | 143 | /* Begin PBXNativeTarget section */ 144 | 50B248B11A17A97300B9D12C /* ShapedImageView */ = { 145 | isa = PBXNativeTarget; 146 | buildConfigurationList = 50B248D51A17A97300B9D12C /* Build configuration list for PBXNativeTarget "ShapedImageView" */; 147 | buildPhases = ( 148 | 50B248AE1A17A97300B9D12C /* Sources */, 149 | 50B248AF1A17A97300B9D12C /* Frameworks */, 150 | 50B248B01A17A97300B9D12C /* Resources */, 151 | ); 152 | buildRules = ( 153 | ); 154 | dependencies = ( 155 | ); 156 | name = ShapedImageView; 157 | productName = ShapedImageView; 158 | productReference = 50B248B21A17A97300B9D12C /* ShapedImageView.app */; 159 | productType = "com.apple.product-type.application"; 160 | }; 161 | 50B248CA1A17A97300B9D12C /* ShapedImageViewTests */ = { 162 | isa = PBXNativeTarget; 163 | buildConfigurationList = 50B248D81A17A97300B9D12C /* Build configuration list for PBXNativeTarget "ShapedImageViewTests" */; 164 | buildPhases = ( 165 | 50B248C71A17A97300B9D12C /* Sources */, 166 | 50B248C81A17A97300B9D12C /* Frameworks */, 167 | 50B248C91A17A97300B9D12C /* Resources */, 168 | ); 169 | buildRules = ( 170 | ); 171 | dependencies = ( 172 | 50B248CD1A17A97300B9D12C /* PBXTargetDependency */, 173 | ); 174 | name = ShapedImageViewTests; 175 | productName = ShapedImageViewTests; 176 | productReference = 50B248CB1A17A97300B9D12C /* ShapedImageViewTests.xctest */; 177 | productType = "com.apple.product-type.bundle.unit-test"; 178 | }; 179 | /* End PBXNativeTarget section */ 180 | 181 | /* Begin PBXProject section */ 182 | 50B248AA1A17A97300B9D12C /* Project object */ = { 183 | isa = PBXProject; 184 | attributes = { 185 | LastUpgradeCheck = 0610; 186 | ORGANIZATIONNAME = Sword; 187 | TargetAttributes = { 188 | 50B248B11A17A97300B9D12C = { 189 | CreatedOnToolsVersion = 6.1; 190 | }; 191 | 50B248CA1A17A97300B9D12C = { 192 | CreatedOnToolsVersion = 6.1; 193 | TestTargetID = 50B248B11A17A97300B9D12C; 194 | }; 195 | }; 196 | }; 197 | buildConfigurationList = 50B248AD1A17A97300B9D12C /* Build configuration list for PBXProject "ShapedImageView" */; 198 | compatibilityVersion = "Xcode 3.2"; 199 | developmentRegion = English; 200 | hasScannedForEncodings = 0; 201 | knownRegions = ( 202 | en, 203 | Base, 204 | ); 205 | mainGroup = 50B248A91A17A97300B9D12C; 206 | productRefGroup = 50B248B31A17A97300B9D12C /* Products */; 207 | projectDirPath = ""; 208 | projectRoot = ""; 209 | targets = ( 210 | 50B248B11A17A97300B9D12C /* ShapedImageView */, 211 | 50B248CA1A17A97300B9D12C /* ShapedImageViewTests */, 212 | ); 213 | }; 214 | /* End PBXProject section */ 215 | 216 | /* Begin PBXResourcesBuildPhase section */ 217 | 50B248B01A17A97300B9D12C /* Resources */ = { 218 | isa = PBXResourcesBuildPhase; 219 | buildActionMask = 2147483647; 220 | files = ( 221 | 5055DC3C1A18BEA500024066 /* gray_bubble_right@2x.png in Resources */, 222 | 50B248C11A17A97300B9D12C /* Main.storyboard in Resources */, 223 | 5055DC3D1A18BEA500024066 /* scenery.jpg in Resources */, 224 | 50B248C61A17A97300B9D12C /* LaunchScreen.xib in Resources */, 225 | 50B248C31A17A97300B9D12C /* Images.xcassets in Resources */, 226 | ); 227 | runOnlyForDeploymentPostprocessing = 0; 228 | }; 229 | 50B248C91A17A97300B9D12C /* Resources */ = { 230 | isa = PBXResourcesBuildPhase; 231 | buildActionMask = 2147483647; 232 | files = ( 233 | ); 234 | runOnlyForDeploymentPostprocessing = 0; 235 | }; 236 | /* End PBXResourcesBuildPhase section */ 237 | 238 | /* Begin PBXSourcesBuildPhase section */ 239 | 50B248AE1A17A97300B9D12C /* Sources */ = { 240 | isa = PBXSourcesBuildPhase; 241 | buildActionMask = 2147483647; 242 | files = ( 243 | 50B248BE1A17A97300B9D12C /* ViewController.m in Sources */, 244 | 50B248BB1A17A97300B9D12C /* AppDelegate.m in Sources */, 245 | 50B248B81A17A97300B9D12C /* main.m in Sources */, 246 | 5055DC381A18B04D00024066 /* HJShapedImageView.m in Sources */, 247 | ); 248 | runOnlyForDeploymentPostprocessing = 0; 249 | }; 250 | 50B248C71A17A97300B9D12C /* Sources */ = { 251 | isa = PBXSourcesBuildPhase; 252 | buildActionMask = 2147483647; 253 | files = ( 254 | 50B248D21A17A97300B9D12C /* ShapedImageViewTests.m in Sources */, 255 | ); 256 | runOnlyForDeploymentPostprocessing = 0; 257 | }; 258 | /* End PBXSourcesBuildPhase section */ 259 | 260 | /* Begin PBXTargetDependency section */ 261 | 50B248CD1A17A97300B9D12C /* PBXTargetDependency */ = { 262 | isa = PBXTargetDependency; 263 | target = 50B248B11A17A97300B9D12C /* ShapedImageView */; 264 | targetProxy = 50B248CC1A17A97300B9D12C /* PBXContainerItemProxy */; 265 | }; 266 | /* End PBXTargetDependency section */ 267 | 268 | /* Begin PBXVariantGroup section */ 269 | 50B248BF1A17A97300B9D12C /* Main.storyboard */ = { 270 | isa = PBXVariantGroup; 271 | children = ( 272 | 50B248C01A17A97300B9D12C /* Base */, 273 | ); 274 | name = Main.storyboard; 275 | sourceTree = ""; 276 | }; 277 | 50B248C41A17A97300B9D12C /* LaunchScreen.xib */ = { 278 | isa = PBXVariantGroup; 279 | children = ( 280 | 50B248C51A17A97300B9D12C /* Base */, 281 | ); 282 | name = LaunchScreen.xib; 283 | sourceTree = ""; 284 | }; 285 | /* End PBXVariantGroup section */ 286 | 287 | /* Begin XCBuildConfiguration section */ 288 | 50B248D31A17A97300B9D12C /* Debug */ = { 289 | isa = XCBuildConfiguration; 290 | buildSettings = { 291 | ALWAYS_SEARCH_USER_PATHS = NO; 292 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 293 | CLANG_CXX_LIBRARY = "libc++"; 294 | CLANG_ENABLE_MODULES = YES; 295 | CLANG_ENABLE_OBJC_ARC = YES; 296 | CLANG_WARN_BOOL_CONVERSION = YES; 297 | CLANG_WARN_CONSTANT_CONVERSION = YES; 298 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 299 | CLANG_WARN_EMPTY_BODY = YES; 300 | CLANG_WARN_ENUM_CONVERSION = YES; 301 | CLANG_WARN_INT_CONVERSION = YES; 302 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 303 | CLANG_WARN_UNREACHABLE_CODE = YES; 304 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 305 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 306 | COPY_PHASE_STRIP = NO; 307 | ENABLE_STRICT_OBJC_MSGSEND = YES; 308 | GCC_C_LANGUAGE_STANDARD = gnu99; 309 | GCC_DYNAMIC_NO_PIC = NO; 310 | GCC_OPTIMIZATION_LEVEL = 0; 311 | GCC_PREPROCESSOR_DEFINITIONS = ( 312 | "DEBUG=1", 313 | "$(inherited)", 314 | ); 315 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 316 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 317 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 318 | GCC_WARN_UNDECLARED_SELECTOR = YES; 319 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 320 | GCC_WARN_UNUSED_FUNCTION = YES; 321 | GCC_WARN_UNUSED_VARIABLE = YES; 322 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 323 | MTL_ENABLE_DEBUG_INFO = YES; 324 | ONLY_ACTIVE_ARCH = YES; 325 | SDKROOT = iphoneos; 326 | }; 327 | name = Debug; 328 | }; 329 | 50B248D41A17A97300B9D12C /* Release */ = { 330 | isa = XCBuildConfiguration; 331 | buildSettings = { 332 | ALWAYS_SEARCH_USER_PATHS = NO; 333 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 334 | CLANG_CXX_LIBRARY = "libc++"; 335 | CLANG_ENABLE_MODULES = YES; 336 | CLANG_ENABLE_OBJC_ARC = YES; 337 | CLANG_WARN_BOOL_CONVERSION = YES; 338 | CLANG_WARN_CONSTANT_CONVERSION = YES; 339 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 340 | CLANG_WARN_EMPTY_BODY = YES; 341 | CLANG_WARN_ENUM_CONVERSION = YES; 342 | CLANG_WARN_INT_CONVERSION = YES; 343 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 344 | CLANG_WARN_UNREACHABLE_CODE = YES; 345 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 346 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 347 | COPY_PHASE_STRIP = YES; 348 | ENABLE_NS_ASSERTIONS = NO; 349 | ENABLE_STRICT_OBJC_MSGSEND = YES; 350 | GCC_C_LANGUAGE_STANDARD = gnu99; 351 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 352 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 353 | GCC_WARN_UNDECLARED_SELECTOR = YES; 354 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 355 | GCC_WARN_UNUSED_FUNCTION = YES; 356 | GCC_WARN_UNUSED_VARIABLE = YES; 357 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 358 | MTL_ENABLE_DEBUG_INFO = NO; 359 | SDKROOT = iphoneos; 360 | VALIDATE_PRODUCT = YES; 361 | }; 362 | name = Release; 363 | }; 364 | 50B248D61A17A97300B9D12C /* Debug */ = { 365 | isa = XCBuildConfiguration; 366 | buildSettings = { 367 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 368 | INFOPLIST_FILE = ShapedImageView/Info.plist; 369 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 370 | PRODUCT_NAME = "$(TARGET_NAME)"; 371 | }; 372 | name = Debug; 373 | }; 374 | 50B248D71A17A97300B9D12C /* Release */ = { 375 | isa = XCBuildConfiguration; 376 | buildSettings = { 377 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 378 | INFOPLIST_FILE = ShapedImageView/Info.plist; 379 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 380 | PRODUCT_NAME = "$(TARGET_NAME)"; 381 | }; 382 | name = Release; 383 | }; 384 | 50B248D91A17A97300B9D12C /* Debug */ = { 385 | isa = XCBuildConfiguration; 386 | buildSettings = { 387 | BUNDLE_LOADER = "$(TEST_HOST)"; 388 | FRAMEWORK_SEARCH_PATHS = ( 389 | "$(SDKROOT)/Developer/Library/Frameworks", 390 | "$(inherited)", 391 | ); 392 | GCC_PREPROCESSOR_DEFINITIONS = ( 393 | "DEBUG=1", 394 | "$(inherited)", 395 | ); 396 | INFOPLIST_FILE = ShapedImageViewTests/Info.plist; 397 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 398 | PRODUCT_NAME = "$(TARGET_NAME)"; 399 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ShapedImageView.app/ShapedImageView"; 400 | }; 401 | name = Debug; 402 | }; 403 | 50B248DA1A17A97300B9D12C /* Release */ = { 404 | isa = XCBuildConfiguration; 405 | buildSettings = { 406 | BUNDLE_LOADER = "$(TEST_HOST)"; 407 | FRAMEWORK_SEARCH_PATHS = ( 408 | "$(SDKROOT)/Developer/Library/Frameworks", 409 | "$(inherited)", 410 | ); 411 | INFOPLIST_FILE = ShapedImageViewTests/Info.plist; 412 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 413 | PRODUCT_NAME = "$(TARGET_NAME)"; 414 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ShapedImageView.app/ShapedImageView"; 415 | }; 416 | name = Release; 417 | }; 418 | /* End XCBuildConfiguration section */ 419 | 420 | /* Begin XCConfigurationList section */ 421 | 50B248AD1A17A97300B9D12C /* Build configuration list for PBXProject "ShapedImageView" */ = { 422 | isa = XCConfigurationList; 423 | buildConfigurations = ( 424 | 50B248D31A17A97300B9D12C /* Debug */, 425 | 50B248D41A17A97300B9D12C /* Release */, 426 | ); 427 | defaultConfigurationIsVisible = 0; 428 | defaultConfigurationName = Release; 429 | }; 430 | 50B248D51A17A97300B9D12C /* Build configuration list for PBXNativeTarget "ShapedImageView" */ = { 431 | isa = XCConfigurationList; 432 | buildConfigurations = ( 433 | 50B248D61A17A97300B9D12C /* Debug */, 434 | 50B248D71A17A97300B9D12C /* Release */, 435 | ); 436 | defaultConfigurationIsVisible = 0; 437 | defaultConfigurationName = Release; 438 | }; 439 | 50B248D81A17A97300B9D12C /* Build configuration list for PBXNativeTarget "ShapedImageViewTests" */ = { 440 | isa = XCConfigurationList; 441 | buildConfigurations = ( 442 | 50B248D91A17A97300B9D12C /* Debug */, 443 | 50B248DA1A17A97300B9D12C /* Release */, 444 | ); 445 | defaultConfigurationIsVisible = 0; 446 | defaultConfigurationName = Release; 447 | }; 448 | /* End XCConfigurationList section */ 449 | }; 450 | rootObject = 50B248AA1A17A97300B9D12C /* Project object */; 451 | } 452 | -------------------------------------------------------------------------------- /ShapedImageView/ShapedImageView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ShapedImageView/ShapedImageView/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // ShapedImageView 4 | // 5 | // Created by Sword on 11/15/14. 6 | // Copyright (c) 2014 Sword. 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 | -------------------------------------------------------------------------------- /ShapedImageView/ShapedImageView/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // ShapedImageView 4 | // 5 | // Created by Sword on 11/15/14. 6 | // Copyright (c) 2014 Sword. 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 | -------------------------------------------------------------------------------- /ShapedImageView/ShapedImageView/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 | -------------------------------------------------------------------------------- /ShapedImageView/ShapedImageView/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 | -------------------------------------------------------------------------------- /ShapedImageView/ShapedImageView/HJShapedImageView.h: -------------------------------------------------------------------------------- 1 | // 2 | // ShapedImageView.h 3 | // ShapedImageView 4 | // 5 | // Created by Sword on 11/16/14. 6 | // Copyright (c) 2014 Sword. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface HJShapedImageView : UIView 12 | 13 | @property (nonatomic, strong) UIImage *image; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /ShapedImageView/ShapedImageView/HJShapedImageView.m: -------------------------------------------------------------------------------- 1 | // 2 | // ShapedImageView.m 3 | // ShapedImageView 4 | // 5 | // Created by Sword on 11/16/14. 6 | // Copyright (c) 2014 Sword. All rights reserved. 7 | // 8 | 9 | #import "HJShapedImageView.h" 10 | 11 | @interface HJShapedImageView() 12 | { 13 | CALayer *_contentLayer; 14 | CAShapeLayer *_maskLayer; 15 | } 16 | @end 17 | 18 | @implementation HJShapedImageView 19 | 20 | - (instancetype)initWithFrame:(CGRect)frame 21 | { 22 | self = [super initWithFrame:frame]; 23 | if (self) { 24 | [self setup]; 25 | } 26 | return self; 27 | } 28 | 29 | 30 | - (void)setup 31 | { 32 | //construct your path 33 | CGMutablePathRef bubblePath = CGPathCreateMutable(); 34 | CGPoint origin = self.bounds.origin; 35 | CGFloat radius = CGRectGetWidth(self.bounds) / 2; 36 | CGPathMoveToPoint(bubblePath, NULL, origin.x, origin.y + 2 *radius); 37 | CGPathMoveToPoint(bubblePath, NULL, origin.x, origin.y + radius); 38 | 39 | CGPathAddArcToPoint(bubblePath, NULL, origin.x, origin.y, origin.x + radius, origin.y, radius); 40 | CGPathAddArcToPoint(bubblePath, NULL, origin.x + 2 * radius, origin.y, origin.x + 2 * radius, origin.y + radius, radius); 41 | CGPathAddArcToPoint(bubblePath, NULL, origin.x + 2 * radius, origin.y + 2 * radius, origin.x + radius, origin.y + 2 * radius, radius); 42 | CGPathAddLineToPoint(bubblePath, NULL, origin.x, origin.y + 2 * radius); 43 | 44 | _maskLayer = [CAShapeLayer layer]; 45 | _maskLayer.fillColor = [UIColor blackColor].CGColor; 46 | _maskLayer.strokeColor = [UIColor clearColor].CGColor; 47 | _maskLayer.frame = self.bounds; 48 | _maskLayer.contentsCenter = CGRectMake(0.5, 0.5, 0.1, 0.1); 49 | 50 | /*! 51 | * 非常关键设置自动拉伸的效果且不变形 52 | */ 53 | _maskLayer.contentsScale = [UIScreen mainScreen].scale; 54 | /*! 55 | * 可以通过conents或path来设置mask,效果不一样 56 | */ 57 | // _maskLayer.contents = (id)[UIImage imageNamed:@"gray_bubble_right@2x.png"].CGImage; 58 | 59 | _maskLayer.path = bubblePath; 60 | CGPathRelease(bubblePath); 61 | 62 | _contentLayer = [CALayer layer]; 63 | _contentLayer.mask = _maskLayer; 64 | _contentLayer.frame = self.bounds; 65 | [self.layer addSublayer:_contentLayer]; 66 | 67 | } 68 | 69 | - (void)setImage:(UIImage *)image 70 | { 71 | _contentLayer.contents = (id)image.CGImage; 72 | } 73 | 74 | @end 75 | -------------------------------------------------------------------------------- /ShapedImageView/ShapedImageView/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 | } -------------------------------------------------------------------------------- /ShapedImageView/ShapedImageView/Images/gray_bubble_right@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heavensword/ShapedImageView/3e3a7e9655f923005ec2ce8cae185acb230b0f14/ShapedImageView/ShapedImageView/Images/gray_bubble_right@2x.png -------------------------------------------------------------------------------- /ShapedImageView/ShapedImageView/Images/scenery.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heavensword/ShapedImageView/3e3a7e9655f923005ec2ce8cae185acb230b0f14/ShapedImageView/ShapedImageView/Images/scenery.jpg -------------------------------------------------------------------------------- /ShapedImageView/ShapedImageView/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.allwayssimple.com.$(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 | -------------------------------------------------------------------------------- /ShapedImageView/ShapedImageView/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // ShapedImageView 4 | // 5 | // Created by Sword on 11/15/14. 6 | // Copyright (c) 2014 Sword. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /ShapedImageView/ShapedImageView/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // ShapedImageView 4 | // 5 | // Created by Sword on 11/15/14. 6 | // Copyright (c) 2014 Sword. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "HJShapedImageView.h" 11 | 12 | @interface ViewController () 13 | 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad 19 | { 20 | [super viewDidLoad]; 21 | self.view.backgroundColor = [UIColor lightGrayColor]; 22 | CGRect frame = CGRectMake((CGRectGetWidth(self.view.bounds) - 100) / 2, (CGRectGetHeight(self.view.bounds) - 150) / 2, 100, 150); 23 | 24 | HJShapedImageView *shapedImageView = [[HJShapedImageView alloc] initWithFrame:frame]; 25 | shapedImageView.image = [UIImage imageNamed:@"scenery.jpg"]; 26 | [self.view addSubview:shapedImageView]; 27 | 28 | // UIImageView *shapedImageView = [[UIImageView alloc] initWithFrame:frame]; 29 | // 30 | // CAShapeLayer *maskLayer = [CAShapeLayer layer]; 31 | //// maskLayer.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 100, 150)].CGPath; 32 | // maskLayer.fillColor = [UIColor blackColor].CGColor; 33 | // maskLayer.strokeColor = [UIColor redColor].CGColor; 34 | // maskLayer.frame = shapedImageView.bounds; 35 | // maskLayer.contents = (id)[UIImage imageNamed:@"gray_bubble_right@2x.png"].CGImage; 36 | // maskLayer.contentsCenter = CGRectMake(0.5, 0.5, 0.1, 0.1); 37 | // maskLayer.contentsScale = [UIScreen mainScreen].scale; 38 | // 39 | // CALayer *shapedLayer = [CALayer layer]; 40 | // shapedLayer.mask = maskLayer; 41 | // shapedLayer.contents = (id)[UIImage imageNamed:@"scenery.jpg"].CGImage; 42 | // shapedLayer.frame = frame; 43 | // [self.view.layer addSublayer:shapedLayer]; 44 | 45 | // shapedImageView.layer.mask = maskLayer; 46 | // shapedImageView.layer.frame = shapedImageView.bounds; 47 | // shapedImageView.image = [UIImage imageNamed:@"scenery.jpg"]; 48 | // [self.view addSubview:shapedImageView]; 49 | // Do any additional setup after loading the view, typically from a nib. 50 | } 51 | 52 | - (void)didReceiveMemoryWarning { 53 | [super didReceiveMemoryWarning]; 54 | // Dispose of any resources that can be recreated. 55 | } 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /ShapedImageView/ShapedImageView/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // ShapedImageView 4 | // 5 | // Created by Sword on 11/15/14. 6 | // Copyright (c) 2014 Sword. 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 | -------------------------------------------------------------------------------- /ShapedImageView/ShapedImageViewTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.allwayssimple.com.$(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 | -------------------------------------------------------------------------------- /ShapedImageView/ShapedImageViewTests/ShapedImageViewTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // ShapedImageViewTests.m 3 | // ShapedImageViewTests 4 | // 5 | // Created by Sword on 11/15/14. 6 | // Copyright (c) 2014 Sword. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface ShapedImageViewTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation ShapedImageViewTests 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 | --------------------------------------------------------------------------------