├── .gitignore ├── LICENSE ├── README.md └── WyhCornerRadius ├── WyhCornerRadius.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── WyhCornerRadius ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ ├── dog1.imageset │ │ ├── Contents.json │ │ └── dog.jpg │ ├── dog2.imageset │ │ ├── Contents.json │ │ └── dog2.jpg │ ├── dog3.imageset │ │ ├── Contents.json │ │ └── dog3.jpg │ ├── dog4.imageset │ │ ├── Contents.json │ │ └── dog4.jpg │ ├── dog5.imageset │ │ ├── Contents.json │ │ └── dog5.jpg │ ├── glb_placeholder.imageset │ │ ├── Contents.json │ │ └── glb_placeholder_icon.png │ └── localImage │ │ ├── Contents.json │ │ ├── local1.imageset │ │ ├── Contents.json │ │ └── local1.jpg │ │ ├── local10.imageset │ │ ├── Contents.json │ │ └── local10.jpg │ │ ├── local2.imageset │ │ ├── Contents.json │ │ └── local2.jpg │ │ ├── local3.imageset │ │ ├── Contents.json │ │ └── local3.jpg │ │ ├── local4.imageset │ │ ├── Contents.json │ │ └── local4.png │ │ ├── local5.imageset │ │ ├── Contents.json │ │ └── local5.jpg │ │ ├── local6.imageset │ │ ├── Contents.json │ │ └── local6.jpg │ │ ├── local7.imageset │ │ ├── Contents.json │ │ └── local7.jpg │ │ ├── local8.imageset │ │ ├── Contents.json │ │ └── local8.jpg │ │ └── local9.imageset │ │ ├── Contents.json │ │ └── local9.png ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── SDWebImage │ ├── NSData+ImageContentType.h │ ├── NSData+ImageContentType.m │ ├── SDImageCache.h │ ├── SDImageCache.m │ ├── SDWebImageCompat.h │ ├── SDWebImageCompat.m │ ├── SDWebImageDecoder.h │ ├── SDWebImageDecoder.m │ ├── SDWebImageDownloader.h │ ├── SDWebImageDownloader.m │ ├── SDWebImageDownloaderOperation.h │ ├── SDWebImageDownloaderOperation.m │ ├── SDWebImageManager.h │ ├── SDWebImageManager.m │ ├── SDWebImageOperation.h │ ├── SDWebImagePrefetcher.h │ ├── SDWebImagePrefetcher.m │ ├── UIButton+WebCache.h │ ├── UIButton+WebCache.m │ ├── UIImage+GIF.h │ ├── UIImage+GIF.m │ ├── UIImage+MultiFormat.h │ ├── UIImage+MultiFormat.m │ ├── UIImageView+HighlightedWebCache.h │ ├── UIImageView+HighlightedWebCache.m │ ├── UIImageView+WebCache.h │ ├── UIImageView+WebCache.m │ ├── UIView+WebCacheOperation.h │ └── UIView+WebCacheOperation.m ├── ViewController.h ├── ViewController.m ├── WyhCornerRadius.podspec ├── WyhCornerRadius │ ├── UIImage+wyhRadius.h │ ├── UIImage+wyhRadius.m │ ├── UIImageView+wyhRadius.h │ ├── UIImageView+wyhRadius.m │ ├── UIView+wyhRadius.h │ ├── UIView+wyhRadius.m │ ├── wyhCornerRadius.h │ └── wyhRadiusConst.h ├── WyhDemoBaseCell.h ├── WyhDemoBaseCell.m ├── WyhDemoListVC │ ├── WyhDemoBaseVC.h │ ├── WyhDemoBaseVC.m │ ├── WyhDemoListVC.h │ ├── WyhDemoListVC.m │ └── WyhImageViewDemo │ │ ├── WyhImageViewDemoCell.h │ │ ├── WyhImageViewDemoCell.m │ │ ├── WyhImageViewDemoVC.h │ │ └── WyhImageViewDemoVC.m └── main.m ├── WyhCornerRadiusTests ├── Info.plist └── WyhCornerRadiusTests.m └── WyhCornerRadiusUITests ├── Info.plist └── WyhCornerRadiusUITests.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | # CocoaPods 32 | # 33 | # We recommend against adding the Pods directory to your .gitignore. However 34 | # you should judge for yourself, the pros and cons are mentioned at: 35 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 36 | # 37 | # Pods/ 38 | 39 | # Carthage 40 | # 41 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 42 | # Carthage/Checkouts 43 | 44 | Carthage/Build 45 | 46 | # fastlane 47 | # 48 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 49 | # screenshots whenever they are needed. 50 | # For more information about the recommended setup visit: 51 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 52 | 53 | fastlane/report.xml 54 | fastlane/Preview.html 55 | fastlane/screenshots 56 | fastlane/test_output 57 | 58 | # Code Injection 59 | # 60 | # After new code Injection tools there's a generated folder /iOSInjectionProject 61 | # https://github.com/johnno1962/injectionforxcode 62 | 63 | iOSInjectionProject/ 64 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WyhCornerRadius 2 | 3 | ![](http://upload-images.jianshu.io/upload_images/4097230-7c9d5d7c2cbee37e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 4 | 5 | Quick and easy to set UIView's corner radius and border(include UIImageView、UIButton、UILabel..)without off-screen Rendering problem in GPU. 6 | 7 | 快速设置UIView的圆角和边框,并且在GPU方面不触发离屏渲染 8 | 9 | ## The rounded corners direction of support : 10 | 11 | UIRectCorner ( UIRectCornerTopLeft、UIRectCornerTopRight、UIRectCornerBottomLeft、UIRectCornerBottomRight、UIRectCornerAllCorners ) 12 | 13 | ## CocoaPods Support 14 | 15 | `pod search WyhCornerRadius` 16 | 17 | ## Example code : 18 | 19 | UIImageView : 20 | 21 | ```objc 22 | //First eg: 23 | [img wyh_autoSetImageCornerRedius:viewWidth/2 ConrnerType:rectCorner Image:[UIImage imageNamed:@"test.jpg"]]; 24 | 25 | //Second eg: 26 | UIImageView *imageView = [UIImageView wyh_circleImageView]; 27 | 28 | ``` 29 | UIButton : 30 | 31 | ```objc 32 | //eg: 33 | [btn wyh_CornerRadius:viewWidth/2 Image:imageNormal RectCornerType:UIRectCornerAllCorners BorderColor:[UIColor blueColor] BorderWidth:3 BackgroundColor:nil UIControlState:(UIControlStateNormal)]; 34 | ``` 35 | UILabel : 36 | 37 | ```objc 38 | //eg: 39 | [label wyh_CornerRadius:viewWidth/2 Image:nil RectCornerType:rectCorner BorderColor:[UIColor magentaColor] BorderWidth:2 BackgroundColor:nil]; 40 | ``` 41 | ## Contact me 42 | 43 | - JianShu: [被帅醒的小吴同志](http://www.jianshu.com/u/b76e3853ae0b) 44 | - Email: 609223770@qq.com 45 | - QQ:609223770 46 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // WyhCornerRadius 4 | // 5 | // Created by wyh on 2017/10/31. 6 | // Copyright © 2017年 wyh. 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 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // WyhCornerRadius 4 | // 5 | // Created by wyh on 2017/10/31. 6 | // Copyright © 2017年 wyh. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "ViewController.h" 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | 20 | self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]; 21 | [self.window makeKeyAndVisible]; 22 | UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:[ViewController new]]; 23 | self.window.rootViewController = navi; 24 | 25 | return YES; 26 | } 27 | 28 | 29 | - (void)applicationWillResignActive:(UIApplication *)application { 30 | // 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. 31 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 32 | } 33 | 34 | 35 | - (void)applicationDidEnterBackground:(UIApplication *)application { 36 | // 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. 37 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 38 | } 39 | 40 | 41 | - (void)applicationWillEnterForeground:(UIApplication *)application { 42 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 43 | } 44 | 45 | 46 | - (void)applicationDidBecomeActive:(UIApplication *)application { 47 | // 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. 48 | } 49 | 50 | 51 | - (void)applicationWillTerminate:(UIApplication *)application { 52 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 53 | } 54 | 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/dog1.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "dog.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/dog1.imageset/dog.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuehengwu/WyhCornerRadius/3666d013bb19e4f394aed05735c947e85248f58e/WyhCornerRadius/WyhCornerRadius/Assets.xcassets/dog1.imageset/dog.jpg -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/dog2.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "dog2.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/dog2.imageset/dog2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuehengwu/WyhCornerRadius/3666d013bb19e4f394aed05735c947e85248f58e/WyhCornerRadius/WyhCornerRadius/Assets.xcassets/dog2.imageset/dog2.jpg -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/dog3.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "dog3.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/dog3.imageset/dog3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuehengwu/WyhCornerRadius/3666d013bb19e4f394aed05735c947e85248f58e/WyhCornerRadius/WyhCornerRadius/Assets.xcassets/dog3.imageset/dog3.jpg -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/dog4.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "dog4.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/dog4.imageset/dog4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuehengwu/WyhCornerRadius/3666d013bb19e4f394aed05735c947e85248f58e/WyhCornerRadius/WyhCornerRadius/Assets.xcassets/dog4.imageset/dog4.jpg -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/dog5.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "dog5.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/dog5.imageset/dog5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuehengwu/WyhCornerRadius/3666d013bb19e4f394aed05735c947e85248f58e/WyhCornerRadius/WyhCornerRadius/Assets.xcassets/dog5.imageset/dog5.jpg -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/glb_placeholder.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "glb_placeholder_icon.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/glb_placeholder.imageset/glb_placeholder_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuehengwu/WyhCornerRadius/3666d013bb19e4f394aed05735c947e85248f58e/WyhCornerRadius/WyhCornerRadius/Assets.xcassets/glb_placeholder.imageset/glb_placeholder_icon.png -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local1.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "local1.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local1.imageset/local1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuehengwu/WyhCornerRadius/3666d013bb19e4f394aed05735c947e85248f58e/WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local1.imageset/local1.jpg -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local10.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "local10.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local10.imageset/local10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuehengwu/WyhCornerRadius/3666d013bb19e4f394aed05735c947e85248f58e/WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local10.imageset/local10.jpg -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local2.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "local2.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local2.imageset/local2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuehengwu/WyhCornerRadius/3666d013bb19e4f394aed05735c947e85248f58e/WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local2.imageset/local2.jpg -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local3.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "local3.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local3.imageset/local3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuehengwu/WyhCornerRadius/3666d013bb19e4f394aed05735c947e85248f58e/WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local3.imageset/local3.jpg -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local4.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "local4.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local4.imageset/local4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuehengwu/WyhCornerRadius/3666d013bb19e4f394aed05735c947e85248f58e/WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local4.imageset/local4.png -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local5.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "local5.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local5.imageset/local5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuehengwu/WyhCornerRadius/3666d013bb19e4f394aed05735c947e85248f58e/WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local5.imageset/local5.jpg -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local6.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "local6.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local6.imageset/local6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuehengwu/WyhCornerRadius/3666d013bb19e4f394aed05735c947e85248f58e/WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local6.imageset/local6.jpg -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local7.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "local7.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local7.imageset/local7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuehengwu/WyhCornerRadius/3666d013bb19e4f394aed05735c947e85248f58e/WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local7.imageset/local7.jpg -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local8.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "local8.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local8.imageset/local8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuehengwu/WyhCornerRadius/3666d013bb19e4f394aed05735c947e85248f58e/WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local8.imageset/local8.jpg -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local9.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "local9.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local9.imageset/local9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuehengwu/WyhCornerRadius/3666d013bb19e4f394aed05735c947e85248f58e/WyhCornerRadius/WyhCornerRadius/Assets.xcassets/localImage/local9.imageset/local9.png -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | HelveticaNeue-BoldItalic 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 32 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSAppTransportSecurity 6 | 7 | NSAllowsArbitraryLoads 8 | 9 | 10 | CFBundleDevelopmentRegion 11 | $(DEVELOPMENT_LANGUAGE) 12 | CFBundleExecutable 13 | $(EXECUTABLE_NAME) 14 | CFBundleIdentifier 15 | $(PRODUCT_BUNDLE_IDENTIFIER) 16 | CFBundleInfoDictionaryVersion 17 | 6.0 18 | CFBundleName 19 | $(PRODUCT_NAME) 20 | CFBundlePackageType 21 | APPL 22 | CFBundleShortVersionString 23 | 1.0 24 | CFBundleVersion 25 | 1 26 | LSRequiresIPhoneOS 27 | 28 | UILaunchStoryboardName 29 | LaunchScreen 30 | UIMainStoryboardFile 31 | Main 32 | UIRequiredDeviceCapabilities 33 | 34 | armv7 35 | 36 | UISupportedInterfaceOrientations 37 | 38 | UIInterfaceOrientationPortrait 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | UISupportedInterfaceOrientations~ipad 43 | 44 | UIInterfaceOrientationPortrait 45 | UIInterfaceOrientationPortraitUpsideDown 46 | UIInterfaceOrientationLandscapeLeft 47 | UIInterfaceOrientationLandscapeRight 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/SDWebImage/NSData+ImageContentType.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Fabrice Aneche on 06/01/14. 3 | // Copyright (c) 2014 Dailymotion. All rights reserved. 4 | // 5 | 6 | #import 7 | 8 | @interface NSData (ImageContentType) 9 | 10 | /** 11 | * Compute the content type for an image data 12 | * 13 | * @param data the input data 14 | * 15 | * @return the content type as string (i.e. image/jpeg, image/gif) 16 | */ 17 | + (NSString *)sd_contentTypeForImageData:(NSData *)data; 18 | 19 | @end 20 | 21 | 22 | @interface NSData (ImageContentTypeDeprecated) 23 | 24 | + (NSString *)contentTypeForImageData:(NSData *)data __deprecated_msg("Use `sd_contentTypeForImageData:`"); 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/SDWebImage/NSData+ImageContentType.m: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Fabrice Aneche on 06/01/14. 3 | // Copyright (c) 2014 Dailymotion. All rights reserved. 4 | // 5 | 6 | #import "NSData+ImageContentType.h" 7 | 8 | 9 | @implementation NSData (ImageContentType) 10 | 11 | + (NSString *)sd_contentTypeForImageData:(NSData *)data { 12 | uint8_t c; 13 | [data getBytes:&c length:1]; 14 | switch (c) { 15 | case 0xFF: 16 | return @"image/jpeg"; 17 | case 0x89: 18 | return @"image/png"; 19 | case 0x47: 20 | return @"image/gif"; 21 | case 0x49: 22 | case 0x4D: 23 | return @"image/tiff"; 24 | case 0x52: 25 | // R as RIFF for WEBP 26 | if ([data length] < 12) { 27 | return nil; 28 | } 29 | 30 | NSString *testString = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(0, 12)] encoding:NSASCIIStringEncoding]; 31 | if ([testString hasPrefix:@"RIFF"] && [testString hasSuffix:@"WEBP"]) { 32 | return @"image/webp"; 33 | } 34 | 35 | return nil; 36 | } 37 | return nil; 38 | } 39 | 40 | @end 41 | 42 | 43 | @implementation NSData (ImageContentTypeDeprecated) 44 | 45 | + (NSString *)contentTypeForImageData:(NSData *)data { 46 | return [self sd_contentTypeForImageData:data]; 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/SDWebImage/SDImageCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import 10 | #import "SDWebImageCompat.h" 11 | 12 | typedef NS_ENUM(NSInteger, SDImageCacheType) { 13 | /** 14 | * The image wasn't available the SDWebImage caches, but was downloaded from the web. 15 | */ 16 | SDImageCacheTypeNone, 17 | /** 18 | * The image was obtained from the disk cache. 19 | */ 20 | SDImageCacheTypeDisk, 21 | /** 22 | * The image was obtained from the memory cache. 23 | */ 24 | SDImageCacheTypeMemory 25 | }; 26 | 27 | typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType cacheType); 28 | 29 | typedef void(^SDWebImageCheckCacheCompletionBlock)(BOOL isInCache); 30 | 31 | typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger totalSize); 32 | 33 | /** 34 | * SDImageCache maintains a memory cache and an optional disk cache. Disk cache write operations are performed 35 | * asynchronous so it doesn’t add unnecessary latency to the UI. 36 | */ 37 | @interface SDImageCache : NSObject 38 | 39 | /** 40 | * Decompressing images that are downloaded and cached can improve performance but can consume lot of memory. 41 | * Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption. 42 | */ 43 | @property (assign, nonatomic) BOOL shouldDecompressImages; 44 | 45 | /** 46 | * disable iCloud backup [defaults to YES] 47 | */ 48 | @property (assign, nonatomic) BOOL shouldDisableiCloud; 49 | 50 | /** 51 | * use memory cache [defaults to YES] 52 | */ 53 | @property (assign, nonatomic) BOOL shouldCacheImagesInMemory; 54 | 55 | /** 56 | * The maximum "total cost" of the in-memory image cache. The cost function is the number of pixels held in memory. 57 | */ 58 | @property (assign, nonatomic) NSUInteger maxMemoryCost; 59 | 60 | /** 61 | * The maximum number of objects the cache should hold. 62 | */ 63 | @property (assign, nonatomic) NSUInteger maxMemoryCountLimit; 64 | 65 | /** 66 | * The maximum length of time to keep an image in the cache, in seconds 67 | */ 68 | @property (assign, nonatomic) NSInteger maxCacheAge; 69 | 70 | /** 71 | * The maximum size of the cache, in bytes. 72 | */ 73 | @property (assign, nonatomic) NSUInteger maxCacheSize; 74 | 75 | /** 76 | * Returns global shared cache instance 77 | * 78 | * @return SDImageCache global instance 79 | */ 80 | + (SDImageCache *)sharedImageCache; 81 | 82 | /** 83 | * Init a new cache store with a specific namespace 84 | * 85 | * @param ns The namespace to use for this cache store 86 | */ 87 | - (id)initWithNamespace:(NSString *)ns; 88 | 89 | /** 90 | * Init a new cache store with a specific namespace and directory 91 | * 92 | * @param ns The namespace to use for this cache store 93 | * @param directory Directory to cache disk images in 94 | */ 95 | - (id)initWithNamespace:(NSString *)ns diskCacheDirectory:(NSString *)directory; 96 | 97 | -(NSString *)makeDiskCachePath:(NSString*)fullNamespace; 98 | 99 | /** 100 | * Add a read-only cache path to search for images pre-cached by SDImageCache 101 | * Useful if you want to bundle pre-loaded images with your app 102 | * 103 | * @param path The path to use for this read-only cache path 104 | */ 105 | - (void)addReadOnlyCachePath:(NSString *)path; 106 | 107 | /** 108 | * Store an image into memory and disk cache at the given key. 109 | * 110 | * @param image The image to store 111 | * @param key The unique image cache key, usually it's image absolute URL 112 | */ 113 | - (void)storeImage:(UIImage *)image forKey:(NSString *)key; 114 | 115 | /** 116 | * Store an image into memory and optionally disk cache at the given key. 117 | * 118 | * @param image The image to store 119 | * @param key The unique image cache key, usually it's image absolute URL 120 | * @param toDisk Store the image to disk cache if YES 121 | */ 122 | - (void)storeImage:(UIImage *)image forKey:(NSString *)key toDisk:(BOOL)toDisk; 123 | 124 | /** 125 | * Store an image into memory and optionally disk cache at the given key. 126 | * 127 | * @param image The image to store 128 | * @param recalculate BOOL indicates if imageData can be used or a new data should be constructed from the UIImage 129 | * @param imageData The image data as returned by the server, this representation will be used for disk storage 130 | * instead of converting the given image object into a storable/compressed image format in order 131 | * to save quality and CPU 132 | * @param key The unique image cache key, usually it's image absolute URL 133 | * @param toDisk Store the image to disk cache if YES 134 | */ 135 | - (void)storeImage:(UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(NSData *)imageData forKey:(NSString *)key toDisk:(BOOL)toDisk; 136 | 137 | /** 138 | * Store image NSData into disk cache at the given key. 139 | * 140 | * @param imageData The image data to store 141 | * @param key The unique image cache key, usually it's image absolute URL 142 | */ 143 | - (void)storeImageDataToDisk:(NSData *)imageData forKey:(NSString *)key; 144 | 145 | /** 146 | * Query the disk cache asynchronously. 147 | * 148 | * @param key The unique key used to store the wanted image 149 | */ 150 | - (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(SDWebImageQueryCompletedBlock)doneBlock; 151 | 152 | /** 153 | * Query the memory cache synchronously. 154 | * 155 | * @param key The unique key used to store the wanted image 156 | */ 157 | - (UIImage *)imageFromMemoryCacheForKey:(NSString *)key; 158 | 159 | /** 160 | * Query the disk cache synchronously after checking the memory cache. 161 | * 162 | * @param key The unique key used to store the wanted image 163 | */ 164 | - (UIImage *)imageFromDiskCacheForKey:(NSString *)key; 165 | 166 | /** 167 | * Remove the image from memory and disk cache synchronously 168 | * 169 | * @param key The unique image cache key 170 | */ 171 | - (void)removeImageForKey:(NSString *)key; 172 | 173 | 174 | /** 175 | * Remove the image from memory and disk cache asynchronously 176 | * 177 | * @param key The unique image cache key 178 | * @param completion An block that should be executed after the image has been removed (optional) 179 | */ 180 | - (void)removeImageForKey:(NSString *)key withCompletion:(SDWebImageNoParamsBlock)completion; 181 | 182 | /** 183 | * Remove the image from memory and optionally disk cache asynchronously 184 | * 185 | * @param key The unique image cache key 186 | * @param fromDisk Also remove cache entry from disk if YES 187 | */ 188 | - (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk; 189 | 190 | /** 191 | * Remove the image from memory and optionally disk cache asynchronously 192 | * 193 | * @param key The unique image cache key 194 | * @param fromDisk Also remove cache entry from disk if YES 195 | * @param completion An block that should be executed after the image has been removed (optional) 196 | */ 197 | - (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(SDWebImageNoParamsBlock)completion; 198 | 199 | /** 200 | * Clear all memory cached images 201 | */ 202 | - (void)clearMemory; 203 | 204 | /** 205 | * Clear all disk cached images. Non-blocking method - returns immediately. 206 | * @param completion An block that should be executed after cache expiration completes (optional) 207 | */ 208 | - (void)clearDiskOnCompletion:(SDWebImageNoParamsBlock)completion; 209 | 210 | /** 211 | * Clear all disk cached images 212 | * @see clearDiskOnCompletion: 213 | */ 214 | - (void)clearDisk; 215 | 216 | /** 217 | * Remove all expired cached image from disk. Non-blocking method - returns immediately. 218 | * @param completionBlock An block that should be executed after cache expiration completes (optional) 219 | */ 220 | - (void)cleanDiskWithCompletionBlock:(SDWebImageNoParamsBlock)completionBlock; 221 | 222 | /** 223 | * Remove all expired cached image from disk 224 | * @see cleanDiskWithCompletionBlock: 225 | */ 226 | - (void)cleanDisk; 227 | 228 | /** 229 | * Get the size used by the disk cache 230 | */ 231 | - (NSUInteger)getSize; 232 | 233 | /** 234 | * Get the number of images in the disk cache 235 | */ 236 | - (NSUInteger)getDiskCount; 237 | 238 | /** 239 | * Asynchronously calculate the disk cache's size. 240 | */ 241 | - (void)calculateSizeWithCompletionBlock:(SDWebImageCalculateSizeBlock)completionBlock; 242 | 243 | /** 244 | * Async check if image exists in disk cache already (does not load the image) 245 | * 246 | * @param key the key describing the url 247 | * @param completionBlock the block to be executed when the check is done. 248 | * @note the completion block will be always executed on the main queue 249 | */ 250 | - (void)diskImageExistsWithKey:(NSString *)key completion:(SDWebImageCheckCacheCompletionBlock)completionBlock; 251 | 252 | /** 253 | * Check if image exists in disk cache already (does not load the image) 254 | * 255 | * @param key the key describing the url 256 | * 257 | * @return YES if an image exists for the given key 258 | */ 259 | - (BOOL)diskImageExistsWithKey:(NSString *)key; 260 | 261 | /** 262 | * Get the cache path for a certain key (needs the cache path root folder) 263 | * 264 | * @param key the key (can be obtained from url using cacheKeyForURL) 265 | * @param path the cache path root folder 266 | * 267 | * @return the cache path 268 | */ 269 | - (NSString *)cachePathForKey:(NSString *)key inPath:(NSString *)path; 270 | 271 | /** 272 | * Get the default cache path for a certain key 273 | * 274 | * @param key the key (can be obtained from url using cacheKeyForURL) 275 | * 276 | * @return the default cache path 277 | */ 278 | - (NSString *)defaultCachePathForKey:(NSString *)key; 279 | 280 | @end 281 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/SDWebImage/SDWebImageCompat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * (c) Jamie Pinkham 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | #import 11 | 12 | #ifdef __OBJC_GC__ 13 | #error SDWebImage does not support Objective-C Garbage Collection 14 | #endif 15 | 16 | #if __IPHONE_OS_VERSION_MIN_REQUIRED != 20000 && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0 17 | #error SDWebImage doesn't support Deployment Target version < 5.0 18 | #endif 19 | 20 | #if !TARGET_OS_IPHONE 21 | #import 22 | #ifndef UIImage 23 | #define UIImage NSImage 24 | #endif 25 | #ifndef UIImageView 26 | #define UIImageView NSImageView 27 | #endif 28 | #else 29 | 30 | #import 31 | 32 | #endif 33 | 34 | #ifndef NS_ENUM 35 | #define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type 36 | #endif 37 | 38 | #ifndef NS_OPTIONS 39 | #define NS_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type 40 | #endif 41 | 42 | #if OS_OBJECT_USE_OBJC 43 | #undef SDDispatchQueueRelease 44 | #undef SDDispatchQueueSetterSementics 45 | #define SDDispatchQueueRelease(q) 46 | #define SDDispatchQueueSetterSementics strong 47 | #else 48 | #undef SDDispatchQueueRelease 49 | #undef SDDispatchQueueSetterSementics 50 | #define SDDispatchQueueRelease(q) (dispatch_release(q)) 51 | #define SDDispatchQueueSetterSementics assign 52 | #endif 53 | 54 | extern UIImage *SDScaledImageForKey(NSString *key, UIImage *image); 55 | 56 | typedef void(^SDWebImageNoParamsBlock)(); 57 | 58 | extern NSString *const SDWebImageErrorDomain; 59 | 60 | #define dispatch_main_sync_safe(block)\ 61 | if ([NSThread isMainThread]) {\ 62 | block();\ 63 | } else {\ 64 | dispatch_sync(dispatch_get_main_queue(), block);\ 65 | } 66 | 67 | #define dispatch_main_async_safe(block)\ 68 | if ([NSThread isMainThread]) {\ 69 | block();\ 70 | } else {\ 71 | dispatch_async(dispatch_get_main_queue(), block);\ 72 | } 73 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/SDWebImage/SDWebImageCompat.m: -------------------------------------------------------------------------------- 1 | // 2 | // SDWebImageCompat.m 3 | // SDWebImage 4 | // 5 | // Created by Olivier Poitrey on 11/12/12. 6 | // Copyright (c) 2012 Dailymotion. All rights reserved. 7 | // 8 | 9 | #import "SDWebImageCompat.h" 10 | 11 | #if !__has_feature(objc_arc) 12 | #error SDWebImage is ARC only. Either turn on ARC for the project or use -fobjc-arc flag 13 | #endif 14 | 15 | inline UIImage *SDScaledImageForKey(NSString *key, UIImage *image) { 16 | if (!image) { 17 | return nil; 18 | } 19 | 20 | if ([image.images count] > 0) { 21 | NSMutableArray *scaledImages = [NSMutableArray array]; 22 | 23 | for (UIImage *tempImage in image.images) { 24 | [scaledImages addObject:SDScaledImageForKey(key, tempImage)]; 25 | } 26 | 27 | return [UIImage animatedImageWithImages:scaledImages duration:image.duration]; 28 | } 29 | else { 30 | if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) { 31 | CGFloat scale = 1; 32 | if (key.length >= 8) { 33 | NSRange range = [key rangeOfString:@"@2x."]; 34 | if (range.location != NSNotFound) { 35 | scale = 2.0; 36 | } 37 | 38 | range = [key rangeOfString:@"@3x."]; 39 | if (range.location != NSNotFound) { 40 | scale = 3.0; 41 | } 42 | } 43 | 44 | UIImage *scaledImage = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:image.imageOrientation]; 45 | image = scaledImage; 46 | } 47 | return image; 48 | } 49 | } 50 | 51 | NSString *const SDWebImageErrorDomain = @"SDWebImageErrorDomain"; 52 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/SDWebImage/SDWebImageDecoder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * Created by james on 9/28/11. 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | #import 12 | #import "SDWebImageCompat.h" 13 | 14 | @interface UIImage (ForceDecode) 15 | 16 | + (UIImage *)decodedImageWithImage:(UIImage *)image; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/SDWebImage/SDWebImageDecoder.m: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * Created by james on 9/28/11. 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | #import "SDWebImageDecoder.h" 12 | 13 | @implementation UIImage (ForceDecode) 14 | 15 | + (UIImage *)decodedImageWithImage:(UIImage *)image { 16 | // while downloading huge amount of images 17 | // autorelease the bitmap context 18 | // and all vars to help system to free memory 19 | // when there are memory warning. 20 | // on iOS7, do not forget to call 21 | // [[SDImageCache sharedImageCache] clearMemory]; 22 | 23 | if (image == nil) { // Prevent "CGBitmapContextCreateImage: invalid context 0x0" error 24 | return nil; 25 | } 26 | 27 | @autoreleasepool{ 28 | // do not decode animated images 29 | if (image.images != nil) { 30 | return image; 31 | } 32 | 33 | CGImageRef imageRef = image.CGImage; 34 | 35 | CGImageAlphaInfo alpha = CGImageGetAlphaInfo(imageRef); 36 | BOOL anyAlpha = (alpha == kCGImageAlphaFirst || 37 | alpha == kCGImageAlphaLast || 38 | alpha == kCGImageAlphaPremultipliedFirst || 39 | alpha == kCGImageAlphaPremultipliedLast); 40 | if (anyAlpha) { 41 | return image; 42 | } 43 | 44 | // current 45 | CGColorSpaceModel imageColorSpaceModel = CGColorSpaceGetModel(CGImageGetColorSpace(imageRef)); 46 | CGColorSpaceRef colorspaceRef = CGImageGetColorSpace(imageRef); 47 | 48 | BOOL unsupportedColorSpace = (imageColorSpaceModel == kCGColorSpaceModelUnknown || 49 | imageColorSpaceModel == kCGColorSpaceModelMonochrome || 50 | imageColorSpaceModel == kCGColorSpaceModelCMYK || 51 | imageColorSpaceModel == kCGColorSpaceModelIndexed); 52 | if (unsupportedColorSpace) { 53 | colorspaceRef = CGColorSpaceCreateDeviceRGB(); 54 | } 55 | 56 | size_t width = CGImageGetWidth(imageRef); 57 | size_t height = CGImageGetHeight(imageRef); 58 | NSUInteger bytesPerPixel = 4; 59 | NSUInteger bytesPerRow = bytesPerPixel * width; 60 | NSUInteger bitsPerComponent = 8; 61 | 62 | 63 | // kCGImageAlphaNone is not supported in CGBitmapContextCreate. 64 | // Since the original image here has no alpha info, use kCGImageAlphaNoneSkipLast 65 | // to create bitmap graphics contexts without alpha info. 66 | CGContextRef context = CGBitmapContextCreate(NULL, 67 | width, 68 | height, 69 | bitsPerComponent, 70 | bytesPerRow, 71 | colorspaceRef, 72 | kCGBitmapByteOrderDefault|kCGImageAlphaNoneSkipLast); 73 | 74 | // Draw the image into the context and retrieve the new bitmap image without alpha 75 | CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); 76 | CGImageRef imageRefWithoutAlpha = CGBitmapContextCreateImage(context); 77 | UIImage *imageWithoutAlpha = [UIImage imageWithCGImage:imageRefWithoutAlpha 78 | scale:image.scale 79 | orientation:image.imageOrientation]; 80 | 81 | if (unsupportedColorSpace) { 82 | CGColorSpaceRelease(colorspaceRef); 83 | } 84 | 85 | CGContextRelease(context); 86 | CGImageRelease(imageRefWithoutAlpha); 87 | 88 | return imageWithoutAlpha; 89 | } 90 | } 91 | 92 | @end 93 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/SDWebImage/SDWebImageDownloader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import 10 | #import "SDWebImageCompat.h" 11 | #import "SDWebImageOperation.h" 12 | 13 | typedef NS_OPTIONS(NSUInteger, SDWebImageDownloaderOptions) { 14 | SDWebImageDownloaderLowPriority = 1 << 0, 15 | SDWebImageDownloaderProgressiveDownload = 1 << 1, 16 | 17 | /** 18 | * By default, request prevent the use of NSURLCache. With this flag, NSURLCache 19 | * is used with default policies. 20 | */ 21 | SDWebImageDownloaderUseNSURLCache = 1 << 2, 22 | 23 | /** 24 | * Call completion block with nil image/imageData if the image was read from NSURLCache 25 | * (to be combined with `SDWebImageDownloaderUseNSURLCache`). 26 | */ 27 | 28 | SDWebImageDownloaderIgnoreCachedResponse = 1 << 3, 29 | /** 30 | * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for 31 | * extra time in background to let the request finish. If the background task expires the operation will be cancelled. 32 | */ 33 | 34 | SDWebImageDownloaderContinueInBackground = 1 << 4, 35 | 36 | /** 37 | * Handles cookies stored in NSHTTPCookieStore by setting 38 | * NSMutableURLRequest.HTTPShouldHandleCookies = YES; 39 | */ 40 | SDWebImageDownloaderHandleCookies = 1 << 5, 41 | 42 | /** 43 | * Enable to allow untrusted SSL certificates. 44 | * Useful for testing purposes. Use with caution in production. 45 | */ 46 | SDWebImageDownloaderAllowInvalidSSLCertificates = 1 << 6, 47 | 48 | /** 49 | * Put the image in the high priority queue. 50 | */ 51 | SDWebImageDownloaderHighPriority = 1 << 7, 52 | }; 53 | 54 | typedef NS_ENUM(NSInteger, SDWebImageDownloaderExecutionOrder) { 55 | /** 56 | * Default value. All download operations will execute in queue style (first-in-first-out). 57 | */ 58 | SDWebImageDownloaderFIFOExecutionOrder, 59 | 60 | /** 61 | * All download operations will execute in stack style (last-in-first-out). 62 | */ 63 | SDWebImageDownloaderLIFOExecutionOrder 64 | }; 65 | 66 | extern NSString *const SDWebImageDownloadStartNotification; 67 | extern NSString *const SDWebImageDownloadStopNotification; 68 | 69 | typedef void(^SDWebImageDownloaderProgressBlock)(NSInteger receivedSize, NSInteger expectedSize); 70 | 71 | typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data, NSError *error, BOOL finished); 72 | 73 | typedef NSDictionary *(^SDWebImageDownloaderHeadersFilterBlock)(NSURL *url, NSDictionary *headers); 74 | 75 | /** 76 | * Asynchronous downloader dedicated and optimized for image loading. 77 | */ 78 | @interface SDWebImageDownloader : NSObject 79 | 80 | /** 81 | * Decompressing images that are downloaded and cached can improve performance but can consume lot of memory. 82 | * Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption. 83 | */ 84 | @property (assign, nonatomic) BOOL shouldDecompressImages; 85 | 86 | @property (assign, nonatomic) NSInteger maxConcurrentDownloads; 87 | 88 | /** 89 | * Shows the current amount of downloads that still need to be downloaded 90 | */ 91 | @property (readonly, nonatomic) NSUInteger currentDownloadCount; 92 | 93 | 94 | /** 95 | * The timeout value (in seconds) for the download operation. Default: 15.0. 96 | */ 97 | @property (assign, nonatomic) NSTimeInterval downloadTimeout; 98 | 99 | 100 | /** 101 | * Changes download operations execution order. Default value is `SDWebImageDownloaderFIFOExecutionOrder`. 102 | */ 103 | @property (assign, nonatomic) SDWebImageDownloaderExecutionOrder executionOrder; 104 | 105 | /** 106 | * Singleton method, returns the shared instance 107 | * 108 | * @return global shared instance of downloader class 109 | */ 110 | + (SDWebImageDownloader *)sharedDownloader; 111 | 112 | /** 113 | * Set the default URL credential to be set for request operations. 114 | */ 115 | @property (strong, nonatomic) NSURLCredential *urlCredential; 116 | 117 | /** 118 | * Set username 119 | */ 120 | @property (strong, nonatomic) NSString *username; 121 | 122 | /** 123 | * Set password 124 | */ 125 | @property (strong, nonatomic) NSString *password; 126 | 127 | /** 128 | * Set filter to pick headers for downloading image HTTP request. 129 | * 130 | * This block will be invoked for each downloading image request, returned 131 | * NSDictionary will be used as headers in corresponding HTTP request. 132 | */ 133 | @property (nonatomic, copy) SDWebImageDownloaderHeadersFilterBlock headersFilter; 134 | 135 | /** 136 | * Set a value for a HTTP header to be appended to each download HTTP request. 137 | * 138 | * @param value The value for the header field. Use `nil` value to remove the header. 139 | * @param field The name of the header field to set. 140 | */ 141 | - (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field; 142 | 143 | /** 144 | * Returns the value of the specified HTTP header field. 145 | * 146 | * @return The value associated with the header field field, or `nil` if there is no corresponding header field. 147 | */ 148 | - (NSString *)valueForHTTPHeaderField:(NSString *)field; 149 | 150 | /** 151 | * Sets a subclass of `SDWebImageDownloaderOperation` as the default 152 | * `NSOperation` to be used each time SDWebImage constructs a request 153 | * operation to download an image. 154 | * 155 | * @param operationClass The subclass of `SDWebImageDownloaderOperation` to set 156 | * as default. Passing `nil` will revert to `SDWebImageDownloaderOperation`. 157 | */ 158 | - (void)setOperationClass:(Class)operationClass; 159 | 160 | /** 161 | * Creates a SDWebImageDownloader async downloader instance with a given URL 162 | * 163 | * The delegate will be informed when the image is finish downloaded or an error has happen. 164 | * 165 | * @see SDWebImageDownloaderDelegate 166 | * 167 | * @param url The URL to the image to download 168 | * @param options The options to be used for this download 169 | * @param progressBlock A block called repeatedly while the image is downloading 170 | * @param completedBlock A block called once the download is completed. 171 | * If the download succeeded, the image parameter is set, in case of error, 172 | * error parameter is set with the error. The last parameter is always YES 173 | * if SDWebImageDownloaderProgressiveDownload isn't use. With the 174 | * SDWebImageDownloaderProgressiveDownload option, this block is called 175 | * repeatedly with the partial image object and the finished argument set to NO 176 | * before to be called a last time with the full image and finished argument 177 | * set to YES. In case of error, the finished argument is always YES. 178 | * 179 | * @return A cancellable SDWebImageOperation 180 | */ 181 | - (id )downloadImageWithURL:(NSURL *)url 182 | options:(SDWebImageDownloaderOptions)options 183 | progress:(SDWebImageDownloaderProgressBlock)progressBlock 184 | completed:(SDWebImageDownloaderCompletedBlock)completedBlock; 185 | 186 | /** 187 | * Sets the download queue suspension state 188 | */ 189 | - (void)setSuspended:(BOOL)suspended; 190 | 191 | /** 192 | * Cancels all download operations in the queue 193 | */ 194 | - (void)cancelAllDownloads; 195 | 196 | @end 197 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/SDWebImage/SDWebImageDownloader.m: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import "SDWebImageDownloader.h" 10 | #import "SDWebImageDownloaderOperation.h" 11 | #import 12 | 13 | static NSString *const kProgressCallbackKey = @"progress"; 14 | static NSString *const kCompletedCallbackKey = @"completed"; 15 | 16 | @interface SDWebImageDownloader () 17 | 18 | @property (strong, nonatomic) NSOperationQueue *downloadQueue; 19 | @property (weak, nonatomic) NSOperation *lastAddedOperation; 20 | @property (assign, nonatomic) Class operationClass; 21 | @property (strong, nonatomic) NSMutableDictionary *URLCallbacks; 22 | @property (strong, nonatomic) NSMutableDictionary *HTTPHeaders; 23 | // This queue is used to serialize the handling of the network responses of all the download operation in a single queue 24 | @property (SDDispatchQueueSetterSementics, nonatomic) dispatch_queue_t barrierQueue; 25 | 26 | @end 27 | 28 | @implementation SDWebImageDownloader 29 | 30 | + (void)initialize { 31 | // Bind SDNetworkActivityIndicator if available (download it here: http://github.com/rs/SDNetworkActivityIndicator ) 32 | // To use it, just add #import "SDNetworkActivityIndicator.h" in addition to the SDWebImage import 33 | if (NSClassFromString(@"SDNetworkActivityIndicator")) { 34 | 35 | #pragma clang diagnostic push 36 | #pragma clang diagnostic ignored "-Warc-performSelector-leaks" 37 | id activityIndicator = [NSClassFromString(@"SDNetworkActivityIndicator") performSelector:NSSelectorFromString(@"sharedActivityIndicator")]; 38 | #pragma clang diagnostic pop 39 | 40 | // Remove observer in case it was previously added. 41 | [[NSNotificationCenter defaultCenter] removeObserver:activityIndicator name:SDWebImageDownloadStartNotification object:nil]; 42 | [[NSNotificationCenter defaultCenter] removeObserver:activityIndicator name:SDWebImageDownloadStopNotification object:nil]; 43 | 44 | [[NSNotificationCenter defaultCenter] addObserver:activityIndicator 45 | selector:NSSelectorFromString(@"startActivity") 46 | name:SDWebImageDownloadStartNotification object:nil]; 47 | [[NSNotificationCenter defaultCenter] addObserver:activityIndicator 48 | selector:NSSelectorFromString(@"stopActivity") 49 | name:SDWebImageDownloadStopNotification object:nil]; 50 | } 51 | } 52 | 53 | + (SDWebImageDownloader *)sharedDownloader { 54 | static dispatch_once_t once; 55 | static id instance; 56 | dispatch_once(&once, ^{ 57 | instance = [self new]; 58 | }); 59 | return instance; 60 | } 61 | 62 | - (id)init { 63 | if ((self = [super init])) { 64 | _operationClass = [SDWebImageDownloaderOperation class]; 65 | _shouldDecompressImages = YES; 66 | _executionOrder = SDWebImageDownloaderFIFOExecutionOrder; 67 | _downloadQueue = [NSOperationQueue new]; 68 | _downloadQueue.maxConcurrentOperationCount = 6; 69 | _URLCallbacks = [NSMutableDictionary new]; 70 | #ifdef SD_WEBP 71 | _HTTPHeaders = [@{@"Accept": @"image/webp,image/*;q=0.8"} mutableCopy]; 72 | #else 73 | _HTTPHeaders = [@{@"Accept": @"image/*;q=0.8"} mutableCopy]; 74 | #endif 75 | _barrierQueue = dispatch_queue_create("com.hackemist.SDWebImageDownloaderBarrierQueue", DISPATCH_QUEUE_CONCURRENT); 76 | _downloadTimeout = 15.0; 77 | } 78 | return self; 79 | } 80 | 81 | - (void)dealloc { 82 | [self.downloadQueue cancelAllOperations]; 83 | SDDispatchQueueRelease(_barrierQueue); 84 | } 85 | 86 | - (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field { 87 | if (value) { 88 | self.HTTPHeaders[field] = value; 89 | } 90 | else { 91 | [self.HTTPHeaders removeObjectForKey:field]; 92 | } 93 | } 94 | 95 | - (NSString *)valueForHTTPHeaderField:(NSString *)field { 96 | return self.HTTPHeaders[field]; 97 | } 98 | 99 | - (void)setMaxConcurrentDownloads:(NSInteger)maxConcurrentDownloads { 100 | _downloadQueue.maxConcurrentOperationCount = maxConcurrentDownloads; 101 | } 102 | 103 | - (NSUInteger)currentDownloadCount { 104 | return _downloadQueue.operationCount; 105 | } 106 | 107 | - (NSInteger)maxConcurrentDownloads { 108 | return _downloadQueue.maxConcurrentOperationCount; 109 | } 110 | 111 | - (void)setOperationClass:(Class)operationClass { 112 | _operationClass = operationClass ?: [SDWebImageDownloaderOperation class]; 113 | } 114 | 115 | - (id )downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageDownloaderCompletedBlock)completedBlock { 116 | __block SDWebImageDownloaderOperation *operation; 117 | __weak __typeof(self)wself = self; 118 | 119 | [self addProgressCallback:progressBlock completedBlock:completedBlock forURL:url createCallback:^{ 120 | NSTimeInterval timeoutInterval = wself.downloadTimeout; 121 | if (timeoutInterval == 0.0) { 122 | timeoutInterval = 15.0; 123 | } 124 | 125 | // In order to prevent from potential duplicate caching (NSURLCache + SDImageCache) we disable the cache for image requests if told otherwise 126 | NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:(options & SDWebImageDownloaderUseNSURLCache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData) timeoutInterval:timeoutInterval]; 127 | request.HTTPShouldHandleCookies = (options & SDWebImageDownloaderHandleCookies); 128 | request.HTTPShouldUsePipelining = YES; 129 | if (wself.headersFilter) { 130 | request.allHTTPHeaderFields = wself.headersFilter(url, [wself.HTTPHeaders copy]); 131 | } 132 | else { 133 | request.allHTTPHeaderFields = wself.HTTPHeaders; 134 | } 135 | operation = [[wself.operationClass alloc] initWithRequest:request 136 | options:options 137 | progress:^(NSInteger receivedSize, NSInteger expectedSize) { 138 | SDWebImageDownloader *sself = wself; 139 | if (!sself) return; 140 | __block NSArray *callbacksForURL; 141 | dispatch_sync(sself.barrierQueue, ^{ 142 | callbacksForURL = [sself.URLCallbacks[url] copy]; 143 | }); 144 | for (NSDictionary *callbacks in callbacksForURL) { 145 | dispatch_async(dispatch_get_main_queue(), ^{ 146 | SDWebImageDownloaderProgressBlock callback = callbacks[kProgressCallbackKey]; 147 | if (callback) callback(receivedSize, expectedSize); 148 | }); 149 | } 150 | } 151 | completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) { 152 | SDWebImageDownloader *sself = wself; 153 | if (!sself) return; 154 | __block NSArray *callbacksForURL; 155 | dispatch_barrier_sync(sself.barrierQueue, ^{ 156 | callbacksForURL = [sself.URLCallbacks[url] copy]; 157 | if (finished) { 158 | [sself.URLCallbacks removeObjectForKey:url]; 159 | } 160 | }); 161 | for (NSDictionary *callbacks in callbacksForURL) { 162 | SDWebImageDownloaderCompletedBlock callback = callbacks[kCompletedCallbackKey]; 163 | if (callback) callback(image, data, error, finished); 164 | } 165 | } 166 | cancelled:^{ 167 | SDWebImageDownloader *sself = wself; 168 | if (!sself) return; 169 | dispatch_barrier_async(sself.barrierQueue, ^{ 170 | [sself.URLCallbacks removeObjectForKey:url]; 171 | }); 172 | }]; 173 | operation.shouldDecompressImages = wself.shouldDecompressImages; 174 | 175 | if (wself.urlCredential) { 176 | operation.credential = wself.urlCredential; 177 | } else if (wself.username && wself.password) { 178 | operation.credential = [NSURLCredential credentialWithUser:wself.username password:wself.password persistence:NSURLCredentialPersistenceForSession]; 179 | } 180 | 181 | if (options & SDWebImageDownloaderHighPriority) { 182 | operation.queuePriority = NSOperationQueuePriorityHigh; 183 | } else if (options & SDWebImageDownloaderLowPriority) { 184 | operation.queuePriority = NSOperationQueuePriorityLow; 185 | } 186 | 187 | [wself.downloadQueue addOperation:operation]; 188 | if (wself.executionOrder == SDWebImageDownloaderLIFOExecutionOrder) { 189 | // Emulate LIFO execution order by systematically adding new operations as last operation's dependency 190 | [wself.lastAddedOperation addDependency:operation]; 191 | wself.lastAddedOperation = operation; 192 | } 193 | }]; 194 | 195 | return operation; 196 | } 197 | 198 | - (void)addProgressCallback:(SDWebImageDownloaderProgressBlock)progressBlock completedBlock:(SDWebImageDownloaderCompletedBlock)completedBlock forURL:(NSURL *)url createCallback:(SDWebImageNoParamsBlock)createCallback { 199 | // The URL will be used as the key to the callbacks dictionary so it cannot be nil. If it is nil immediately call the completed block with no image or data. 200 | if (url == nil) { 201 | if (completedBlock != nil) { 202 | completedBlock(nil, nil, nil, NO); 203 | } 204 | return; 205 | } 206 | 207 | dispatch_barrier_sync(self.barrierQueue, ^{ 208 | BOOL first = NO; 209 | if (!self.URLCallbacks[url]) { 210 | self.URLCallbacks[url] = [NSMutableArray new]; 211 | first = YES; 212 | } 213 | 214 | // Handle single download of simultaneous download request for the same URL 215 | NSMutableArray *callbacksForURL = self.URLCallbacks[url]; 216 | NSMutableDictionary *callbacks = [NSMutableDictionary new]; 217 | if (progressBlock) callbacks[kProgressCallbackKey] = [progressBlock copy]; 218 | if (completedBlock) callbacks[kCompletedCallbackKey] = [completedBlock copy]; 219 | [callbacksForURL addObject:callbacks]; 220 | self.URLCallbacks[url] = callbacksForURL; 221 | 222 | if (first) { 223 | createCallback(); 224 | } 225 | }); 226 | } 227 | 228 | - (void)setSuspended:(BOOL)suspended { 229 | [self.downloadQueue setSuspended:suspended]; 230 | } 231 | 232 | - (void)cancelAllDownloads { 233 | [self.downloadQueue cancelAllOperations]; 234 | } 235 | 236 | @end 237 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/SDWebImage/SDWebImageDownloaderOperation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import 10 | #import "SDWebImageDownloader.h" 11 | #import "SDWebImageOperation.h" 12 | 13 | extern NSString *const SDWebImageDownloadStartNotification; 14 | extern NSString *const SDWebImageDownloadReceiveResponseNotification; 15 | extern NSString *const SDWebImageDownloadStopNotification; 16 | extern NSString *const SDWebImageDownloadFinishNotification; 17 | 18 | @interface SDWebImageDownloaderOperation : NSOperation 19 | 20 | /** 21 | * The request used by the operation's connection. 22 | */ 23 | @property (strong, nonatomic, readonly) NSURLRequest *request; 24 | 25 | 26 | @property (assign, nonatomic) BOOL shouldDecompressImages; 27 | 28 | /** 29 | * Whether the URL connection should consult the credential storage for authenticating the connection. `YES` by default. 30 | * 31 | * This is the value that is returned in the `NSURLConnectionDelegate` method `-connectionShouldUseCredentialStorage:`. 32 | */ 33 | @property (nonatomic, assign) BOOL shouldUseCredentialStorage; 34 | 35 | /** 36 | * The credential used for authentication challenges in `-connection:didReceiveAuthenticationChallenge:`. 37 | * 38 | * This will be overridden by any shared credentials that exist for the username or password of the request URL, if present. 39 | */ 40 | @property (nonatomic, strong) NSURLCredential *credential; 41 | 42 | /** 43 | * The SDWebImageDownloaderOptions for the receiver. 44 | */ 45 | @property (assign, nonatomic, readonly) SDWebImageDownloaderOptions options; 46 | 47 | /** 48 | * The expected size of data. 49 | */ 50 | @property (assign, nonatomic) NSInteger expectedSize; 51 | 52 | /** 53 | * The response returned by the operation's connection. 54 | */ 55 | @property (strong, nonatomic) NSURLResponse *response; 56 | 57 | /** 58 | * Initializes a `SDWebImageDownloaderOperation` object 59 | * 60 | * @see SDWebImageDownloaderOperation 61 | * 62 | * @param request the URL request 63 | * @param options downloader options 64 | * @param progressBlock the block executed when a new chunk of data arrives. 65 | * @note the progress block is executed on a background queue 66 | * @param completedBlock the block executed when the download is done. 67 | * @note the completed block is executed on the main queue for success. If errors are found, there is a chance the block will be executed on a background queue 68 | * @param cancelBlock the block executed if the download (operation) is cancelled 69 | * 70 | * @return the initialized instance 71 | */ 72 | - (id)initWithRequest:(NSURLRequest *)request 73 | options:(SDWebImageDownloaderOptions)options 74 | progress:(SDWebImageDownloaderProgressBlock)progressBlock 75 | completed:(SDWebImageDownloaderCompletedBlock)completedBlock 76 | cancelled:(SDWebImageNoParamsBlock)cancelBlock; 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/SDWebImage/SDWebImageManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import "SDWebImageCompat.h" 10 | #import "SDWebImageOperation.h" 11 | #import "SDWebImageDownloader.h" 12 | #import "SDImageCache.h" 13 | 14 | typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) { 15 | /** 16 | * By default, when a URL fail to be downloaded, the URL is blacklisted so the library won't keep trying. 17 | * This flag disable this blacklisting. 18 | */ 19 | SDWebImageRetryFailed = 1 << 0, 20 | 21 | /** 22 | * By default, image downloads are started during UI interactions, this flags disable this feature, 23 | * leading to delayed download on UIScrollView deceleration for instance. 24 | */ 25 | SDWebImageLowPriority = 1 << 1, 26 | 27 | /** 28 | * This flag disables on-disk caching 29 | */ 30 | SDWebImageCacheMemoryOnly = 1 << 2, 31 | 32 | /** 33 | * This flag enables progressive download, the image is displayed progressively during download as a browser would do. 34 | * By default, the image is only displayed once completely downloaded. 35 | */ 36 | SDWebImageProgressiveDownload = 1 << 3, 37 | 38 | /** 39 | * Even if the image is cached, respect the HTTP response cache control, and refresh the image from remote location if needed. 40 | * The disk caching will be handled by NSURLCache instead of SDWebImage leading to slight performance degradation. 41 | * This option helps deal with images changing behind the same request URL, e.g. Facebook graph api profile pics. 42 | * If a cached image is refreshed, the completion block is called once with the cached image and again with the final image. 43 | * 44 | * Use this flag only if you can't make your URLs static with embedded cache busting parameter. 45 | */ 46 | SDWebImageRefreshCached = 1 << 4, 47 | 48 | /** 49 | * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for 50 | * extra time in background to let the request finish. If the background task expires the operation will be cancelled. 51 | */ 52 | SDWebImageContinueInBackground = 1 << 5, 53 | 54 | /** 55 | * Handles cookies stored in NSHTTPCookieStore by setting 56 | * NSMutableURLRequest.HTTPShouldHandleCookies = YES; 57 | */ 58 | SDWebImageHandleCookies = 1 << 6, 59 | 60 | /** 61 | * Enable to allow untrusted SSL certificates. 62 | * Useful for testing purposes. Use with caution in production. 63 | */ 64 | SDWebImageAllowInvalidSSLCertificates = 1 << 7, 65 | 66 | /** 67 | * By default, images are loaded in the order in which they were queued. This flag moves them to 68 | * the front of the queue. 69 | */ 70 | SDWebImageHighPriority = 1 << 8, 71 | 72 | /** 73 | * By default, placeholder images are loaded while the image is loading. This flag will delay the loading 74 | * of the placeholder image until after the image has finished loading. 75 | */ 76 | SDWebImageDelayPlaceholder = 1 << 9, 77 | 78 | /** 79 | * We usually don't call transformDownloadedImage delegate method on animated images, 80 | * as most transformation code would mangle it. 81 | * Use this flag to transform them anyway. 82 | */ 83 | SDWebImageTransformAnimatedImage = 1 << 10, 84 | 85 | /** 86 | * By default, image is added to the imageView after download. But in some cases, we want to 87 | * have the hand before setting the image (apply a filter or add it with cross-fade animation for instance) 88 | * Use this flag if you want to manually set the image in the completion when success 89 | */ 90 | SDWebImageAvoidAutoSetImage = 1 << 11 91 | }; 92 | 93 | typedef void(^SDWebImageCompletionBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL); 94 | 95 | typedef void(^SDWebImageCompletionWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL); 96 | 97 | typedef NSString *(^SDWebImageCacheKeyFilterBlock)(NSURL *url); 98 | 99 | 100 | @class SDWebImageManager; 101 | 102 | @protocol SDWebImageManagerDelegate 103 | 104 | @optional 105 | 106 | /** 107 | * Controls which image should be downloaded when the image is not found in the cache. 108 | * 109 | * @param imageManager The current `SDWebImageManager` 110 | * @param imageURL The url of the image to be downloaded 111 | * 112 | * @return Return NO to prevent the downloading of the image on cache misses. If not implemented, YES is implied. 113 | */ 114 | - (BOOL)imageManager:(SDWebImageManager *)imageManager shouldDownloadImageForURL:(NSURL *)imageURL; 115 | 116 | /** 117 | * Allows to transform the image immediately after it has been downloaded and just before to cache it on disk and memory. 118 | * NOTE: This method is called from a global queue in order to not to block the main thread. 119 | * 120 | * @param imageManager The current `SDWebImageManager` 121 | * @param image The image to transform 122 | * @param imageURL The url of the image to transform 123 | * 124 | * @return The transformed image object. 125 | */ 126 | - (UIImage *)imageManager:(SDWebImageManager *)imageManager transformDownloadedImage:(UIImage *)image withURL:(NSURL *)imageURL; 127 | 128 | @end 129 | 130 | /** 131 | * The SDWebImageManager is the class behind the UIImageView+WebCache category and likes. 132 | * It ties the asynchronous downloader (SDWebImageDownloader) with the image cache store (SDImageCache). 133 | * You can use this class directly to benefit from web image downloading with caching in another context than 134 | * a UIView. 135 | * 136 | * Here is a simple example of how to use SDWebImageManager: 137 | * 138 | * @code 139 | 140 | SDWebImageManager *manager = [SDWebImageManager sharedManager]; 141 | [manager downloadImageWithURL:imageURL 142 | options:0 143 | progress:nil 144 | completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { 145 | if (image) { 146 | // do something with image 147 | } 148 | }]; 149 | 150 | * @endcode 151 | */ 152 | @interface SDWebImageManager : NSObject 153 | 154 | @property (weak, nonatomic) id delegate; 155 | 156 | @property (strong, nonatomic, readonly) SDImageCache *imageCache; 157 | @property (strong, nonatomic, readonly) SDWebImageDownloader *imageDownloader; 158 | 159 | /** 160 | * The cache filter is a block used each time SDWebImageManager need to convert an URL into a cache key. This can 161 | * be used to remove dynamic part of an image URL. 162 | * 163 | * The following example sets a filter in the application delegate that will remove any query-string from the 164 | * URL before to use it as a cache key: 165 | * 166 | * @code 167 | 168 | [[SDWebImageManager sharedManager] setCacheKeyFilter:^(NSURL *url) { 169 | url = [[NSURL alloc] initWithScheme:url.scheme host:url.host path:url.path]; 170 | return [url absoluteString]; 171 | }]; 172 | 173 | * @endcode 174 | */ 175 | @property (nonatomic, copy) SDWebImageCacheKeyFilterBlock cacheKeyFilter; 176 | 177 | /** 178 | * Returns global SDWebImageManager instance. 179 | * 180 | * @return SDWebImageManager shared instance 181 | */ 182 | + (SDWebImageManager *)sharedManager; 183 | 184 | /** 185 | * Downloads the image at the given URL if not present in cache or return the cached version otherwise. 186 | * 187 | * @param url The URL to the image 188 | * @param options A mask to specify options to use for this request 189 | * @param progressBlock A block called while image is downloading 190 | * @param completedBlock A block called when operation has been completed. 191 | * 192 | * This parameter is required. 193 | * 194 | * This block has no return value and takes the requested UIImage as first parameter. 195 | * In case of error the image parameter is nil and the second parameter may contain an NSError. 196 | * 197 | * The third parameter is an `SDImageCacheType` enum indicating if the image was retrieved from the local cache 198 | * or from the memory cache or from the network. 199 | * 200 | * The last parameter is set to NO when the SDWebImageProgressiveDownload option is used and the image is 201 | * downloading. This block is thus called repeatedly with a partial image. When image is fully downloaded, the 202 | * block is called a last time with the full image and the last parameter set to YES. 203 | * 204 | * @return Returns an NSObject conforming to SDWebImageOperation. Should be an instance of SDWebImageDownloaderOperation 205 | */ 206 | - (id )downloadImageWithURL:(NSURL *)url 207 | options:(SDWebImageOptions)options 208 | progress:(SDWebImageDownloaderProgressBlock)progressBlock 209 | completed:(SDWebImageCompletionWithFinishedBlock)completedBlock; 210 | 211 | /** 212 | * Saves image to cache for given URL 213 | * 214 | * @param image The image to cache 215 | * @param url The URL to the image 216 | * 217 | */ 218 | 219 | - (void)saveImageToCache:(UIImage *)image forURL:(NSURL *)url; 220 | 221 | /** 222 | * Cancel all current operations 223 | */ 224 | - (void)cancelAll; 225 | 226 | /** 227 | * Check one or more operations running 228 | */ 229 | - (BOOL)isRunning; 230 | 231 | /** 232 | * Check if image has already been cached 233 | * 234 | * @param url image url 235 | * 236 | * @return if the image was already cached 237 | */ 238 | - (BOOL)cachedImageExistsForURL:(NSURL *)url; 239 | 240 | /** 241 | * Check if image has already been cached on disk only 242 | * 243 | * @param url image url 244 | * 245 | * @return if the image was already cached (disk only) 246 | */ 247 | - (BOOL)diskImageExistsForURL:(NSURL *)url; 248 | 249 | /** 250 | * Async check if image has already been cached 251 | * 252 | * @param url image url 253 | * @param completionBlock the block to be executed when the check is finished 254 | * 255 | * @note the completion block is always executed on the main queue 256 | */ 257 | - (void)cachedImageExistsForURL:(NSURL *)url 258 | completion:(SDWebImageCheckCacheCompletionBlock)completionBlock; 259 | 260 | /** 261 | * Async check if image has already been cached on disk only 262 | * 263 | * @param url image url 264 | * @param completionBlock the block to be executed when the check is finished 265 | * 266 | * @note the completion block is always executed on the main queue 267 | */ 268 | - (void)diskImageExistsForURL:(NSURL *)url 269 | completion:(SDWebImageCheckCacheCompletionBlock)completionBlock; 270 | 271 | 272 | /** 273 | *Return the cache key for a given URL 274 | */ 275 | - (NSString *)cacheKeyForURL:(NSURL *)url; 276 | 277 | @end 278 | 279 | 280 | #pragma mark - Deprecated 281 | 282 | typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType) __deprecated_msg("Block type deprecated. Use `SDWebImageCompletionBlock`"); 283 | typedef void(^SDWebImageCompletedWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) __deprecated_msg("Block type deprecated. Use `SDWebImageCompletionWithFinishedBlock`"); 284 | 285 | 286 | @interface SDWebImageManager (Deprecated) 287 | 288 | /** 289 | * Downloads the image at the given URL if not present in cache or return the cached version otherwise. 290 | * 291 | * @deprecated This method has been deprecated. Use `downloadImageWithURL:options:progress:completed:` 292 | */ 293 | - (id )downloadWithURL:(NSURL *)url 294 | options:(SDWebImageOptions)options 295 | progress:(SDWebImageDownloaderProgressBlock)progressBlock 296 | completed:(SDWebImageCompletedWithFinishedBlock)completedBlock __deprecated_msg("Method deprecated. Use `downloadImageWithURL:options:progress:completed:`"); 297 | 298 | @end 299 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/SDWebImage/SDWebImageOperation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import 10 | 11 | @protocol SDWebImageOperation 12 | 13 | - (void)cancel; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/SDWebImage/SDWebImagePrefetcher.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import 10 | #import "SDWebImageManager.h" 11 | 12 | @class SDWebImagePrefetcher; 13 | 14 | @protocol SDWebImagePrefetcherDelegate 15 | 16 | @optional 17 | 18 | /** 19 | * Called when an image was prefetched. 20 | * 21 | * @param imagePrefetcher The current image prefetcher 22 | * @param imageURL The image url that was prefetched 23 | * @param finishedCount The total number of images that were prefetched (successful or not) 24 | * @param totalCount The total number of images that were to be prefetched 25 | */ 26 | - (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didPrefetchURL:(NSURL *)imageURL finishedCount:(NSUInteger)finishedCount totalCount:(NSUInteger)totalCount; 27 | 28 | /** 29 | * Called when all images are prefetched. 30 | * @param imagePrefetcher The current image prefetcher 31 | * @param totalCount The total number of images that were prefetched (whether successful or not) 32 | * @param skippedCount The total number of images that were skipped 33 | */ 34 | - (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount; 35 | 36 | @end 37 | 38 | typedef void(^SDWebImagePrefetcherProgressBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls); 39 | typedef void(^SDWebImagePrefetcherCompletionBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls); 40 | 41 | /** 42 | * Prefetch some URLs in the cache for future use. Images are downloaded in low priority. 43 | */ 44 | @interface SDWebImagePrefetcher : NSObject 45 | 46 | /** 47 | * The web image manager 48 | */ 49 | @property (strong, nonatomic, readonly) SDWebImageManager *manager; 50 | 51 | /** 52 | * Maximum number of URLs to prefetch at the same time. Defaults to 3. 53 | */ 54 | @property (nonatomic, assign) NSUInteger maxConcurrentDownloads; 55 | 56 | /** 57 | * SDWebImageOptions for prefetcher. Defaults to SDWebImageLowPriority. 58 | */ 59 | @property (nonatomic, assign) SDWebImageOptions options; 60 | 61 | /** 62 | * Queue options for Prefetcher. Defaults to Main Queue. 63 | */ 64 | @property (nonatomic, assign) dispatch_queue_t prefetcherQueue; 65 | 66 | @property (weak, nonatomic) id delegate; 67 | 68 | /** 69 | * Return the global image prefetcher instance. 70 | */ 71 | + (SDWebImagePrefetcher *)sharedImagePrefetcher; 72 | 73 | /** 74 | * Allows you to instantiate a prefetcher with any arbitrary image manager. 75 | */ 76 | - (id)initWithImageManager:(SDWebImageManager *)manager; 77 | 78 | /** 79 | * Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching, 80 | * currently one image is downloaded at a time, 81 | * and skips images for failed downloads and proceed to the next image in the list 82 | * 83 | * @param urls list of URLs to prefetch 84 | */ 85 | - (void)prefetchURLs:(NSArray *)urls; 86 | 87 | /** 88 | * Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching, 89 | * currently one image is downloaded at a time, 90 | * and skips images for failed downloads and proceed to the next image in the list 91 | * 92 | * @param urls list of URLs to prefetch 93 | * @param progressBlock block to be called when progress updates; 94 | * first parameter is the number of completed (successful or not) requests, 95 | * second parameter is the total number of images originally requested to be prefetched 96 | * @param completionBlock block to be called when prefetching is completed 97 | * first param is the number of completed (successful or not) requests, 98 | * second parameter is the number of skipped requests 99 | */ 100 | - (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock; 101 | 102 | /** 103 | * Remove and cancel queued list 104 | */ 105 | - (void)cancelPrefetching; 106 | 107 | 108 | @end 109 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/SDWebImage/SDWebImagePrefetcher.m: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import "SDWebImagePrefetcher.h" 10 | 11 | @interface SDWebImagePrefetcher () 12 | 13 | @property (strong, nonatomic) SDWebImageManager *manager; 14 | @property (strong, nonatomic) NSArray *prefetchURLs; 15 | @property (assign, nonatomic) NSUInteger requestedCount; 16 | @property (assign, nonatomic) NSUInteger skippedCount; 17 | @property (assign, nonatomic) NSUInteger finishedCount; 18 | @property (assign, nonatomic) NSTimeInterval startedTime; 19 | @property (copy, nonatomic) SDWebImagePrefetcherCompletionBlock completionBlock; 20 | @property (copy, nonatomic) SDWebImagePrefetcherProgressBlock progressBlock; 21 | 22 | @end 23 | 24 | @implementation SDWebImagePrefetcher 25 | 26 | + (SDWebImagePrefetcher *)sharedImagePrefetcher { 27 | static dispatch_once_t once; 28 | static id instance; 29 | dispatch_once(&once, ^{ 30 | instance = [self new]; 31 | }); 32 | return instance; 33 | } 34 | 35 | - (id)init { 36 | return [self initWithImageManager:[SDWebImageManager new]]; 37 | } 38 | 39 | - (id)initWithImageManager:(SDWebImageManager *)manager { 40 | if ((self = [super init])) { 41 | _manager = manager; 42 | _options = SDWebImageLowPriority; 43 | _prefetcherQueue = dispatch_get_main_queue(); 44 | self.maxConcurrentDownloads = 3; 45 | } 46 | return self; 47 | } 48 | 49 | - (void)setMaxConcurrentDownloads:(NSUInteger)maxConcurrentDownloads { 50 | self.manager.imageDownloader.maxConcurrentDownloads = maxConcurrentDownloads; 51 | } 52 | 53 | - (NSUInteger)maxConcurrentDownloads { 54 | return self.manager.imageDownloader.maxConcurrentDownloads; 55 | } 56 | 57 | - (void)startPrefetchingAtIndex:(NSUInteger)index { 58 | if (index >= self.prefetchURLs.count) return; 59 | self.requestedCount++; 60 | [self.manager downloadImageWithURL:self.prefetchURLs[index] options:self.options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { 61 | if (!finished) return; 62 | self.finishedCount++; 63 | 64 | if (image) { 65 | if (self.progressBlock) { 66 | self.progressBlock(self.finishedCount,[self.prefetchURLs count]); 67 | } 68 | } 69 | else { 70 | if (self.progressBlock) { 71 | self.progressBlock(self.finishedCount,[self.prefetchURLs count]); 72 | } 73 | // Add last failed 74 | self.skippedCount++; 75 | } 76 | if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didPrefetchURL:finishedCount:totalCount:)]) { 77 | [self.delegate imagePrefetcher:self 78 | didPrefetchURL:self.prefetchURLs[index] 79 | finishedCount:self.finishedCount 80 | totalCount:self.prefetchURLs.count 81 | ]; 82 | } 83 | if (self.prefetchURLs.count > self.requestedCount) { 84 | dispatch_async(self.prefetcherQueue, ^{ 85 | [self startPrefetchingAtIndex:self.requestedCount]; 86 | }); 87 | } else if (self.finishedCount == self.requestedCount) { 88 | [self reportStatus]; 89 | if (self.completionBlock) { 90 | self.completionBlock(self.finishedCount, self.skippedCount); 91 | self.completionBlock = nil; 92 | } 93 | self.progressBlock = nil; 94 | } 95 | }]; 96 | } 97 | 98 | - (void)reportStatus { 99 | NSUInteger total = [self.prefetchURLs count]; 100 | if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didFinishWithTotalCount:skippedCount:)]) { 101 | [self.delegate imagePrefetcher:self 102 | didFinishWithTotalCount:(total - self.skippedCount) 103 | skippedCount:self.skippedCount 104 | ]; 105 | } 106 | } 107 | 108 | - (void)prefetchURLs:(NSArray *)urls { 109 | [self prefetchURLs:urls progress:nil completed:nil]; 110 | } 111 | 112 | - (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock { 113 | [self cancelPrefetching]; // Prevent duplicate prefetch request 114 | self.startedTime = CFAbsoluteTimeGetCurrent(); 115 | self.prefetchURLs = urls; 116 | self.completionBlock = completionBlock; 117 | self.progressBlock = progressBlock; 118 | 119 | if (urls.count == 0) { 120 | if (completionBlock) { 121 | completionBlock(0,0); 122 | } 123 | } else { 124 | // Starts prefetching from the very first image on the list with the max allowed concurrency 125 | NSUInteger listCount = self.prefetchURLs.count; 126 | for (NSUInteger i = 0; i < self.maxConcurrentDownloads && self.requestedCount < listCount; i++) { 127 | [self startPrefetchingAtIndex:i]; 128 | } 129 | } 130 | } 131 | 132 | - (void)cancelPrefetching { 133 | self.prefetchURLs = nil; 134 | self.skippedCount = 0; 135 | self.requestedCount = 0; 136 | self.finishedCount = 0; 137 | [self.manager cancelAll]; 138 | } 139 | 140 | @end 141 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/SDWebImage/UIButton+WebCache.m: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import "UIButton+WebCache.h" 10 | #import "objc/runtime.h" 11 | #import "UIView+WebCacheOperation.h" 12 | 13 | static char imageURLStorageKey; 14 | 15 | @implementation UIButton (WebCache) 16 | 17 | - (NSURL *)sd_currentImageURL { 18 | NSURL *url = self.imageURLStorage[@(self.state)]; 19 | 20 | if (!url) { 21 | url = self.imageURLStorage[@(UIControlStateNormal)]; 22 | } 23 | 24 | return url; 25 | } 26 | 27 | - (NSURL *)sd_imageURLForState:(UIControlState)state { 28 | return self.imageURLStorage[@(state)]; 29 | } 30 | 31 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state { 32 | [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; 33 | } 34 | 35 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { 36 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; 37 | } 38 | 39 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { 40 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; 41 | } 42 | 43 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock { 44 | [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock]; 45 | } 46 | 47 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock { 48 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock]; 49 | } 50 | 51 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { 52 | 53 | [self setImage:placeholder forState:state]; 54 | [self sd_cancelImageLoadForState:state]; 55 | 56 | if (!url) { 57 | [self.imageURLStorage removeObjectForKey:@(state)]; 58 | 59 | dispatch_main_async_safe(^{ 60 | if (completedBlock) { 61 | NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; 62 | completedBlock(nil, error, SDImageCacheTypeNone, url); 63 | } 64 | }); 65 | 66 | return; 67 | } 68 | 69 | self.imageURLStorage[@(state)] = url; 70 | 71 | __weak __typeof(self)wself = self; 72 | id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { 73 | if (!wself) return; 74 | dispatch_main_sync_safe(^{ 75 | __strong UIButton *sself = wself; 76 | if (!sself) return; 77 | if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock) 78 | { 79 | completedBlock(image, error, cacheType, url); 80 | return; 81 | } 82 | else if (image) { 83 | [sself setImage:image forState:state]; 84 | } 85 | if (completedBlock && finished) { 86 | completedBlock(image, error, cacheType, url); 87 | } 88 | }); 89 | }]; 90 | [self sd_setImageLoadOperation:operation forState:state]; 91 | } 92 | 93 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state { 94 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; 95 | } 96 | 97 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { 98 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; 99 | } 100 | 101 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { 102 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; 103 | } 104 | 105 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock { 106 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock]; 107 | } 108 | 109 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock { 110 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock]; 111 | } 112 | 113 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { 114 | [self sd_cancelBackgroundImageLoadForState:state]; 115 | 116 | [self setBackgroundImage:placeholder forState:state]; 117 | 118 | if (url) { 119 | __weak __typeof(self)wself = self; 120 | id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { 121 | if (!wself) return; 122 | dispatch_main_sync_safe(^{ 123 | __strong UIButton *sself = wself; 124 | if (!sself) return; 125 | if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock) 126 | { 127 | completedBlock(image, error, cacheType, url); 128 | return; 129 | } 130 | else if (image) { 131 | [sself setBackgroundImage:image forState:state]; 132 | } 133 | if (completedBlock && finished) { 134 | completedBlock(image, error, cacheType, url); 135 | } 136 | }); 137 | }]; 138 | [self sd_setBackgroundImageLoadOperation:operation forState:state]; 139 | } else { 140 | dispatch_main_async_safe(^{ 141 | NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; 142 | if (completedBlock) { 143 | completedBlock(nil, error, SDImageCacheTypeNone, url); 144 | } 145 | }); 146 | } 147 | } 148 | 149 | - (void)sd_setImageLoadOperation:(id)operation forState:(UIControlState)state { 150 | [self sd_setImageLoadOperation:operation forKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(state)]]; 151 | } 152 | 153 | - (void)sd_cancelImageLoadForState:(UIControlState)state { 154 | [self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(state)]]; 155 | } 156 | 157 | - (void)sd_setBackgroundImageLoadOperation:(id)operation forState:(UIControlState)state { 158 | [self sd_setImageLoadOperation:operation forKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]]; 159 | } 160 | 161 | - (void)sd_cancelBackgroundImageLoadForState:(UIControlState)state { 162 | [self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]]; 163 | } 164 | 165 | - (NSMutableDictionary *)imageURLStorage { 166 | NSMutableDictionary *storage = objc_getAssociatedObject(self, &imageURLStorageKey); 167 | if (!storage) 168 | { 169 | storage = [NSMutableDictionary dictionary]; 170 | objc_setAssociatedObject(self, &imageURLStorageKey, storage, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 171 | } 172 | 173 | return storage; 174 | } 175 | 176 | @end 177 | 178 | 179 | @implementation UIButton (WebCacheDeprecated) 180 | 181 | - (NSURL *)currentImageURL { 182 | return [self sd_currentImageURL]; 183 | } 184 | 185 | - (NSURL *)imageURLForState:(UIControlState)state { 186 | return [self sd_imageURLForState:state]; 187 | } 188 | 189 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state { 190 | [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; 191 | } 192 | 193 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { 194 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; 195 | } 196 | 197 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { 198 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; 199 | } 200 | 201 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock { 202 | [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 203 | if (completedBlock) { 204 | completedBlock(image, error, cacheType); 205 | } 206 | }]; 207 | } 208 | 209 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock { 210 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 211 | if (completedBlock) { 212 | completedBlock(image, error, cacheType); 213 | } 214 | }]; 215 | } 216 | 217 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { 218 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 219 | if (completedBlock) { 220 | completedBlock(image, error, cacheType); 221 | } 222 | }]; 223 | } 224 | 225 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state { 226 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; 227 | } 228 | 229 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { 230 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; 231 | } 232 | 233 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { 234 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; 235 | } 236 | 237 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock { 238 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 239 | if (completedBlock) { 240 | completedBlock(image, error, cacheType); 241 | } 242 | }]; 243 | } 244 | 245 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock { 246 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 247 | if (completedBlock) { 248 | completedBlock(image, error, cacheType); 249 | } 250 | }]; 251 | } 252 | 253 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { 254 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 255 | if (completedBlock) { 256 | completedBlock(image, error, cacheType); 257 | } 258 | }]; 259 | } 260 | 261 | - (void)cancelCurrentImageLoad { 262 | // in a backwards compatible manner, cancel for current state 263 | [self sd_cancelImageLoadForState:self.state]; 264 | } 265 | 266 | - (void)cancelBackgroundImageLoadForState:(UIControlState)state { 267 | [self sd_cancelBackgroundImageLoadForState:state]; 268 | } 269 | 270 | @end 271 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/SDWebImage/UIImage+GIF.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+GIF.h 3 | // LBGIFImage 4 | // 5 | // Created by Laurin Brandner on 06.01.12. 6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIImage (GIF) 12 | 13 | + (UIImage *)sd_animatedGIFNamed:(NSString *)name; 14 | 15 | + (UIImage *)sd_animatedGIFWithData:(NSData *)data; 16 | 17 | - (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/SDWebImage/UIImage+GIF.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+GIF.m 3 | // LBGIFImage 4 | // 5 | // Created by Laurin Brandner on 06.01.12. 6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "UIImage+GIF.h" 10 | #import 11 | 12 | @implementation UIImage (GIF) 13 | 14 | + (UIImage *)sd_animatedGIFWithData:(NSData *)data { 15 | if (!data) { 16 | return nil; 17 | } 18 | 19 | CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL); 20 | 21 | size_t count = CGImageSourceGetCount(source); 22 | 23 | UIImage *animatedImage; 24 | 25 | if (count <= 1) { 26 | animatedImage = [[UIImage alloc] initWithData:data]; 27 | } 28 | else { 29 | NSMutableArray *images = [NSMutableArray array]; 30 | 31 | NSTimeInterval duration = 0.0f; 32 | 33 | for (size_t i = 0; i < count; i++) { 34 | CGImageRef image = CGImageSourceCreateImageAtIndex(source, i, NULL); 35 | if (!image) { 36 | continue; 37 | } 38 | 39 | duration += [self sd_frameDurationAtIndex:i source:source]; 40 | 41 | [images addObject:[UIImage imageWithCGImage:image scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp]]; 42 | 43 | CGImageRelease(image); 44 | } 45 | 46 | if (!duration) { 47 | duration = (1.0f / 10.0f) * count; 48 | } 49 | 50 | animatedImage = [UIImage animatedImageWithImages:images duration:duration]; 51 | } 52 | 53 | CFRelease(source); 54 | 55 | return animatedImage; 56 | } 57 | 58 | + (float)sd_frameDurationAtIndex:(NSUInteger)index source:(CGImageSourceRef)source { 59 | float frameDuration = 0.1f; 60 | CFDictionaryRef cfFrameProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil); 61 | NSDictionary *frameProperties = (__bridge NSDictionary *)cfFrameProperties; 62 | NSDictionary *gifProperties = frameProperties[(NSString *)kCGImagePropertyGIFDictionary]; 63 | 64 | NSNumber *delayTimeUnclampedProp = gifProperties[(NSString *)kCGImagePropertyGIFUnclampedDelayTime]; 65 | if (delayTimeUnclampedProp) { 66 | frameDuration = [delayTimeUnclampedProp floatValue]; 67 | } 68 | else { 69 | 70 | NSNumber *delayTimeProp = gifProperties[(NSString *)kCGImagePropertyGIFDelayTime]; 71 | if (delayTimeProp) { 72 | frameDuration = [delayTimeProp floatValue]; 73 | } 74 | } 75 | 76 | // Many annoying ads specify a 0 duration to make an image flash as quickly as possible. 77 | // We follow Firefox's behavior and use a duration of 100 ms for any frames that specify 78 | // a duration of <= 10 ms. See and 79 | // for more information. 80 | 81 | if (frameDuration < 0.011f) { 82 | frameDuration = 0.100f; 83 | } 84 | 85 | CFRelease(cfFrameProperties); 86 | return frameDuration; 87 | } 88 | 89 | + (UIImage *)sd_animatedGIFNamed:(NSString *)name { 90 | CGFloat scale = [UIScreen mainScreen].scale; 91 | 92 | if (scale > 1.0f) { 93 | NSString *retinaPath = [[NSBundle mainBundle] pathForResource:[name stringByAppendingString:@"@2x"] ofType:@"gif"]; 94 | 95 | NSData *data = [NSData dataWithContentsOfFile:retinaPath]; 96 | 97 | if (data) { 98 | return [UIImage sd_animatedGIFWithData:data]; 99 | } 100 | 101 | NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"]; 102 | 103 | data = [NSData dataWithContentsOfFile:path]; 104 | 105 | if (data) { 106 | return [UIImage sd_animatedGIFWithData:data]; 107 | } 108 | 109 | return [UIImage imageNamed:name]; 110 | } 111 | else { 112 | NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"]; 113 | 114 | NSData *data = [NSData dataWithContentsOfFile:path]; 115 | 116 | if (data) { 117 | return [UIImage sd_animatedGIFWithData:data]; 118 | } 119 | 120 | return [UIImage imageNamed:name]; 121 | } 122 | } 123 | 124 | - (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size { 125 | if (CGSizeEqualToSize(self.size, size) || CGSizeEqualToSize(size, CGSizeZero)) { 126 | return self; 127 | } 128 | 129 | CGSize scaledSize = size; 130 | CGPoint thumbnailPoint = CGPointZero; 131 | 132 | CGFloat widthFactor = size.width / self.size.width; 133 | CGFloat heightFactor = size.height / self.size.height; 134 | CGFloat scaleFactor = (widthFactor > heightFactor) ? widthFactor : heightFactor; 135 | scaledSize.width = self.size.width * scaleFactor; 136 | scaledSize.height = self.size.height * scaleFactor; 137 | 138 | if (widthFactor > heightFactor) { 139 | thumbnailPoint.y = (size.height - scaledSize.height) * 0.5; 140 | } 141 | else if (widthFactor < heightFactor) { 142 | thumbnailPoint.x = (size.width - scaledSize.width) * 0.5; 143 | } 144 | 145 | NSMutableArray *scaledImages = [NSMutableArray array]; 146 | 147 | for (UIImage *image in self.images) { 148 | UIGraphicsBeginImageContextWithOptions(size, NO, 0.0); 149 | 150 | [image drawInRect:CGRectMake(thumbnailPoint.x, thumbnailPoint.y, scaledSize.width, scaledSize.height)]; 151 | UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 152 | 153 | [scaledImages addObject:newImage]; 154 | 155 | UIGraphicsEndImageContext(); 156 | } 157 | 158 | return [UIImage animatedImageWithImages:scaledImages duration:self.duration]; 159 | } 160 | 161 | @end 162 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/SDWebImage/UIImage+MultiFormat.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+MultiFormat.h 3 | // SDWebImage 4 | // 5 | // Created by Olivier Poitrey on 07/06/13. 6 | // Copyright (c) 2013 Dailymotion. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIImage (MultiFormat) 12 | 13 | + (UIImage *)sd_imageWithData:(NSData *)data; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/SDWebImage/UIImage+MultiFormat.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+MultiFormat.m 3 | // SDWebImage 4 | // 5 | // Created by Olivier Poitrey on 07/06/13. 6 | // Copyright (c) 2013 Dailymotion. All rights reserved. 7 | // 8 | 9 | #import "UIImage+MultiFormat.h" 10 | #import "UIImage+GIF.h" 11 | #import "NSData+ImageContentType.h" 12 | #import 13 | 14 | #ifdef SD_WEBP 15 | #import "UIImage+WebP.h" 16 | #endif 17 | 18 | @implementation UIImage (MultiFormat) 19 | 20 | + (UIImage *)sd_imageWithData:(NSData *)data { 21 | if (!data) { 22 | return nil; 23 | } 24 | 25 | UIImage *image; 26 | NSString *imageContentType = [NSData sd_contentTypeForImageData:data]; 27 | if ([imageContentType isEqualToString:@"image/gif"]) { 28 | image = [UIImage sd_animatedGIFWithData:data]; 29 | } 30 | #ifdef SD_WEBP 31 | else if ([imageContentType isEqualToString:@"image/webp"]) 32 | { 33 | image = [UIImage sd_imageWithWebPData:data]; 34 | } 35 | #endif 36 | else { 37 | image = [[UIImage alloc] initWithData:data]; 38 | UIImageOrientation orientation = [self sd_imageOrientationFromImageData:data]; 39 | if (orientation != UIImageOrientationUp) { 40 | image = [UIImage imageWithCGImage:image.CGImage 41 | scale:image.scale 42 | orientation:orientation]; 43 | } 44 | } 45 | 46 | 47 | return image; 48 | } 49 | 50 | 51 | +(UIImageOrientation)sd_imageOrientationFromImageData:(NSData *)imageData { 52 | UIImageOrientation result = UIImageOrientationUp; 53 | CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL); 54 | if (imageSource) { 55 | CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL); 56 | if (properties) { 57 | CFTypeRef val; 58 | int exifOrientation; 59 | val = CFDictionaryGetValue(properties, kCGImagePropertyOrientation); 60 | if (val) { 61 | CFNumberGetValue(val, kCFNumberIntType, &exifOrientation); 62 | result = [self sd_exifOrientationToiOSOrientation:exifOrientation]; 63 | } // else - if it's not set it remains at up 64 | CFRelease((CFTypeRef) properties); 65 | } else { 66 | //NSLog(@"NO PROPERTIES, FAIL"); 67 | } 68 | CFRelease(imageSource); 69 | } 70 | return result; 71 | } 72 | 73 | #pragma mark EXIF orientation tag converter 74 | // Convert an EXIF image orientation to an iOS one. 75 | // reference see here: http://sylvana.net/jpegcrop/exif_orientation.html 76 | + (UIImageOrientation) sd_exifOrientationToiOSOrientation:(int)exifOrientation { 77 | UIImageOrientation orientation = UIImageOrientationUp; 78 | switch (exifOrientation) { 79 | case 1: 80 | orientation = UIImageOrientationUp; 81 | break; 82 | 83 | case 3: 84 | orientation = UIImageOrientationDown; 85 | break; 86 | 87 | case 8: 88 | orientation = UIImageOrientationLeft; 89 | break; 90 | 91 | case 6: 92 | orientation = UIImageOrientationRight; 93 | break; 94 | 95 | case 2: 96 | orientation = UIImageOrientationUpMirrored; 97 | break; 98 | 99 | case 4: 100 | orientation = UIImageOrientationDownMirrored; 101 | break; 102 | 103 | case 5: 104 | orientation = UIImageOrientationLeftMirrored; 105 | break; 106 | 107 | case 7: 108 | orientation = UIImageOrientationRightMirrored; 109 | break; 110 | default: 111 | break; 112 | } 113 | return orientation; 114 | } 115 | 116 | 117 | 118 | @end 119 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/SDWebImage/UIImageView+HighlightedWebCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import 10 | #import "SDWebImageCompat.h" 11 | #import "SDWebImageManager.h" 12 | 13 | /** 14 | * Integrates SDWebImage async downloading and caching of remote images with UIImageView for highlighted state. 15 | */ 16 | @interface UIImageView (HighlightedWebCache) 17 | 18 | /** 19 | * Set the imageView `highlightedImage` with an `url`. 20 | * 21 | * The download is asynchronous and cached. 22 | * 23 | * @param url The url for the image. 24 | */ 25 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url; 26 | 27 | /** 28 | * Set the imageView `highlightedImage` with an `url` and custom options. 29 | * 30 | * The download is asynchronous and cached. 31 | * 32 | * @param url The url for the image. 33 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. 34 | */ 35 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options; 36 | 37 | /** 38 | * Set the imageView `highlightedImage` with an `url`. 39 | * 40 | * The download is asynchronous and cached. 41 | * 42 | * @param url The url for the image. 43 | * @param completedBlock A block called when operation has been completed. This block has no return value 44 | * and takes the requested UIImage as first parameter. In case of error the image parameter 45 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 46 | * indicating if the image was retrieved from the local cache or from the network. 47 | * The fourth parameter is the original image url. 48 | */ 49 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock; 50 | 51 | /** 52 | * Set the imageView `highlightedImage` with an `url` and custom options. 53 | * 54 | * The download is asynchronous and cached. 55 | * 56 | * @param url The url for the image. 57 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. 58 | * @param completedBlock A block called when operation has been completed. This block has no return value 59 | * and takes the requested UIImage as first parameter. In case of error the image parameter 60 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 61 | * indicating if the image was retrieved from the local cache or from the network. 62 | * The fourth parameter is the original image url. 63 | */ 64 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; 65 | 66 | /** 67 | * Set the imageView `highlightedImage` with an `url` and custom options. 68 | * 69 | * The download is asynchronous and cached. 70 | * 71 | * @param url The url for the image. 72 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. 73 | * @param progressBlock A block called while image is downloading 74 | * @param completedBlock A block called when operation has been completed. This block has no return value 75 | * and takes the requested UIImage as first parameter. In case of error the image parameter 76 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 77 | * indicating if the image was retrieved from the local cache or from the network. 78 | * The fourth parameter is the original image url. 79 | */ 80 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock; 81 | 82 | /** 83 | * Cancel the current download 84 | */ 85 | - (void)sd_cancelCurrentHighlightedImageLoad; 86 | 87 | @end 88 | 89 | 90 | @interface UIImageView (HighlightedWebCacheDeprecated) 91 | 92 | - (void)setHighlightedImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:`"); 93 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:`"); 94 | - (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:completed:`"); 95 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:completed:`"); 96 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:progress:completed:`"); 97 | 98 | - (void)cancelCurrentHighlightedImageLoad __deprecated_msg("Use `sd_cancelCurrentHighlightedImageLoad`"); 99 | 100 | @end 101 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/SDWebImage/UIImageView+HighlightedWebCache.m: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import "UIImageView+HighlightedWebCache.h" 10 | #import "UIView+WebCacheOperation.h" 11 | 12 | #define UIImageViewHighlightedWebCacheOperationKey @"highlightedImage" 13 | 14 | @implementation UIImageView (HighlightedWebCache) 15 | 16 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url { 17 | [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil]; 18 | } 19 | 20 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options { 21 | [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil]; 22 | } 23 | 24 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock { 25 | [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock]; 26 | } 27 | 28 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { 29 | [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:completedBlock]; 30 | } 31 | 32 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock { 33 | [self sd_cancelCurrentHighlightedImageLoad]; 34 | 35 | if (url) { 36 | __weak __typeof(self)wself = self; 37 | id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { 38 | if (!wself) return; 39 | dispatch_main_sync_safe (^ 40 | { 41 | if (!wself) return; 42 | if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock) 43 | { 44 | completedBlock(image, error, cacheType, url); 45 | return; 46 | } 47 | else if (image) { 48 | wself.highlightedImage = image; 49 | [wself setNeedsLayout]; 50 | } 51 | if (completedBlock && finished) { 52 | completedBlock(image, error, cacheType, url); 53 | } 54 | }); 55 | }]; 56 | [self sd_setImageLoadOperation:operation forKey:UIImageViewHighlightedWebCacheOperationKey]; 57 | } else { 58 | dispatch_main_async_safe(^{ 59 | NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; 60 | if (completedBlock) { 61 | completedBlock(nil, error, SDImageCacheTypeNone, url); 62 | } 63 | }); 64 | } 65 | } 66 | 67 | - (void)sd_cancelCurrentHighlightedImageLoad { 68 | [self sd_cancelImageLoadOperationWithKey:UIImageViewHighlightedWebCacheOperationKey]; 69 | } 70 | 71 | @end 72 | 73 | 74 | @implementation UIImageView (HighlightedWebCacheDeprecated) 75 | 76 | - (void)setHighlightedImageWithURL:(NSURL *)url { 77 | [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil]; 78 | } 79 | 80 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options { 81 | [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil]; 82 | } 83 | 84 | - (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock { 85 | [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 86 | if (completedBlock) { 87 | completedBlock(image, error, cacheType); 88 | } 89 | }]; 90 | } 91 | 92 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { 93 | [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 94 | if (completedBlock) { 95 | completedBlock(image, error, cacheType); 96 | } 97 | }]; 98 | } 99 | 100 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock { 101 | [self sd_setHighlightedImageWithURL:url options:0 progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 102 | if (completedBlock) { 103 | completedBlock(image, error, cacheType); 104 | } 105 | }]; 106 | } 107 | 108 | - (void)cancelCurrentHighlightedImageLoad { 109 | [self sd_cancelCurrentHighlightedImageLoad]; 110 | } 111 | 112 | @end 113 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/SDWebImage/UIImageView+WebCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import "SDWebImageCompat.h" 10 | #import "SDWebImageManager.h" 11 | 12 | /** 13 | * Integrates SDWebImage async downloading and caching of remote images with UIImageView. 14 | * 15 | * Usage with a UITableViewCell sub-class: 16 | * 17 | * @code 18 | 19 | #import 20 | 21 | ... 22 | 23 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 24 | { 25 | static NSString *MyIdentifier = @"MyIdentifier"; 26 | 27 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 28 | 29 | if (cell == nil) { 30 | cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] 31 | autorelease]; 32 | } 33 | 34 | // Here we use the provided sd_setImageWithURL: method to load the web image 35 | // Ensure you use a placeholder image otherwise cells will be initialized with no image 36 | [cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"] 37 | placeholderImage:[UIImage imageNamed:@"placeholder"]]; 38 | 39 | cell.textLabel.text = @"My Text"; 40 | return cell; 41 | } 42 | 43 | * @endcode 44 | */ 45 | @interface UIImageView (WebCache) 46 | 47 | /** 48 | * Get the current image URL. 49 | * 50 | * Note that because of the limitations of categories this property can get out of sync 51 | * if you use sd_setImage: directly. 52 | */ 53 | - (NSURL *)sd_imageURL; 54 | 55 | /** 56 | * Set the imageView `image` with an `url`. 57 | * 58 | * The download is asynchronous and cached. 59 | * 60 | * @param url The url for the image. 61 | */ 62 | - (void)sd_setImageWithURL:(NSURL *)url; 63 | 64 | /** 65 | * Set the imageView `image` with an `url` and a placeholder. 66 | * 67 | * The download is asynchronous and cached. 68 | * 69 | * @param url The url for the image. 70 | * @param placeholder The image to be set initially, until the image request finishes. 71 | * @see sd_setImageWithURL:placeholderImage:options: 72 | */ 73 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder; 74 | 75 | /** 76 | * Set the imageView `image` with an `url`, placeholder and custom options. 77 | * 78 | * The download is asynchronous and cached. 79 | * 80 | * @param url The url for the image. 81 | * @param placeholder The image to be set initially, until the image request finishes. 82 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. 83 | */ 84 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; 85 | 86 | /** 87 | * Set the imageView `image` with an `url`. 88 | * 89 | * The download is asynchronous and cached. 90 | * 91 | * @param url The url for the image. 92 | * @param completedBlock A block called when operation has been completed. This block has no return value 93 | * and takes the requested UIImage as first parameter. In case of error the image parameter 94 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 95 | * indicating if the image was retrieved from the local cache or from the network. 96 | * The fourth parameter is the original image url. 97 | */ 98 | - (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock; 99 | 100 | /** 101 | * Set the imageView `image` with an `url`, placeholder. 102 | * 103 | * The download is asynchronous and cached. 104 | * 105 | * @param url The url for the image. 106 | * @param placeholder The image to be set initially, until the image request finishes. 107 | * @param completedBlock A block called when operation has been completed. This block has no return value 108 | * and takes the requested UIImage as first parameter. In case of error the image parameter 109 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 110 | * indicating if the image was retrieved from the local cache or from the network. 111 | * The fourth parameter is the original image url. 112 | */ 113 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; 114 | 115 | /** 116 | * Set the imageView `image` with an `url`, placeholder and custom options. 117 | * 118 | * The download is asynchronous and cached. 119 | * 120 | * @param url The url for the image. 121 | * @param placeholder The image to be set initially, until the image request finishes. 122 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. 123 | * @param completedBlock A block called when operation has been completed. This block has no return value 124 | * and takes the requested UIImage as first parameter. In case of error the image parameter 125 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 126 | * indicating if the image was retrieved from the local cache or from the network. 127 | * The fourth parameter is the original image url. 128 | */ 129 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; 130 | 131 | /** 132 | * Set the imageView `image` with an `url`, placeholder and custom options. 133 | * 134 | * The download is asynchronous and cached. 135 | * 136 | * @param url The url for the image. 137 | * @param placeholder The image to be set initially, until the image request finishes. 138 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. 139 | * @param progressBlock A block called while image is downloading 140 | * @param completedBlock A block called when operation has been completed. This block has no return value 141 | * and takes the requested UIImage as first parameter. In case of error the image parameter 142 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 143 | * indicating if the image was retrieved from the local cache or from the network. 144 | * The fourth parameter is the original image url. 145 | */ 146 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock; 147 | 148 | /** 149 | * Set the imageView `image` with an `url` and optionally a placeholder image. 150 | * 151 | * The download is asynchronous and cached. 152 | * 153 | * @param url The url for the image. 154 | * @param placeholder The image to be set initially, until the image request finishes. 155 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. 156 | * @param progressBlock A block called while image is downloading 157 | * @param completedBlock A block called when operation has been completed. This block has no return value 158 | * and takes the requested UIImage as first parameter. In case of error the image parameter 159 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 160 | * indicating if the image was retrieved from the local cache or from the network. 161 | * The fourth parameter is the original image url. 162 | */ 163 | - (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock; 164 | 165 | /** 166 | * Download an array of images and starts them in an animation loop 167 | * 168 | * @param arrayOfURLs An array of NSURL 169 | */ 170 | - (void)sd_setAnimationImagesWithURLs:(NSArray *)arrayOfURLs; 171 | 172 | /** 173 | * Cancel the current download 174 | */ 175 | - (void)sd_cancelCurrentImageLoad; 176 | 177 | - (void)sd_cancelCurrentAnimationImagesLoad; 178 | 179 | /** 180 | * Show activity UIActivityIndicatorView 181 | */ 182 | - (void)setShowActivityIndicatorView:(BOOL)show; 183 | 184 | /** 185 | * set desired UIActivityIndicatorViewStyle 186 | * 187 | * @param style The style of the UIActivityIndicatorView 188 | */ 189 | - (void)setIndicatorStyle:(UIActivityIndicatorViewStyle)style; 190 | 191 | @end 192 | 193 | 194 | @interface UIImageView (WebCacheDeprecated) 195 | 196 | - (NSURL *)imageURL __deprecated_msg("Use `sd_imageURL`"); 197 | 198 | - (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:`"); 199 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:`"); 200 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options`"); 201 | 202 | - (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:completed:`"); 203 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:completed:`"); 204 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:completed:`"); 205 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:progress:completed:`"); 206 | 207 | - (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url andPlaceholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithPreviousCachedImageWithURL:placeholderImage:options:progress:completed:`"); 208 | 209 | - (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs __deprecated_msg("Use `sd_setAnimationImagesWithURLs:`"); 210 | 211 | - (void)cancelCurrentArrayLoad __deprecated_msg("Use `sd_cancelCurrentAnimationImagesLoad`"); 212 | 213 | - (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelCurrentImageLoad`"); 214 | 215 | @end 216 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/SDWebImage/UIView+WebCacheOperation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import 10 | #import "SDWebImageManager.h" 11 | 12 | @interface UIView (WebCacheOperation) 13 | 14 | /** 15 | * Set the image load operation (storage in a UIView based dictionary) 16 | * 17 | * @param operation the operation 18 | * @param key key for storing the operation 19 | */ 20 | - (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key; 21 | 22 | /** 23 | * Cancel all operations for the current UIView and key 24 | * 25 | * @param key key for identifying the operations 26 | */ 27 | - (void)sd_cancelImageLoadOperationWithKey:(NSString *)key; 28 | 29 | /** 30 | * Just remove the operations corresponding to the current UIView and key without cancelling them 31 | * 32 | * @param key key for identifying the operations 33 | */ 34 | - (void)sd_removeImageLoadOperationWithKey:(NSString *)key; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/SDWebImage/UIView+WebCacheOperation.m: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import "UIView+WebCacheOperation.h" 10 | #import "objc/runtime.h" 11 | 12 | static char loadOperationKey; 13 | 14 | @implementation UIView (WebCacheOperation) 15 | 16 | - (NSMutableDictionary *)operationDictionary { 17 | NSMutableDictionary *operations = objc_getAssociatedObject(self, &loadOperationKey); 18 | if (operations) { 19 | return operations; 20 | } 21 | operations = [NSMutableDictionary dictionary]; 22 | objc_setAssociatedObject(self, &loadOperationKey, operations, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 23 | return operations; 24 | } 25 | 26 | - (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key { 27 | [self sd_cancelImageLoadOperationWithKey:key]; 28 | NSMutableDictionary *operationDictionary = [self operationDictionary]; 29 | [operationDictionary setObject:operation forKey:key]; 30 | } 31 | 32 | - (void)sd_cancelImageLoadOperationWithKey:(NSString *)key { 33 | // Cancel in progress downloader from queue 34 | NSMutableDictionary *operationDictionary = [self operationDictionary]; 35 | id operations = [operationDictionary objectForKey:key]; 36 | if (operations) { 37 | if ([operations isKindOfClass:[NSArray class]]) { 38 | for (id operation in operations) { 39 | if (operation) { 40 | [operation cancel]; 41 | } 42 | } 43 | } else if ([operations conformsToProtocol:@protocol(SDWebImageOperation)]){ 44 | [(id) operations cancel]; 45 | } 46 | [operationDictionary removeObjectForKey:key]; 47 | } 48 | } 49 | 50 | - (void)sd_removeImageLoadOperationWithKey:(NSString *)key { 51 | NSMutableDictionary *operationDictionary = [self operationDictionary]; 52 | [operationDictionary removeObjectForKey:key]; 53 | } 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // WyhCornerRadius 4 | // 5 | // Created by wyh on 2017/10/31. 6 | // Copyright © 2017年 wyh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // WyhCornerRadius 4 | // 5 | // Created by wyh on 2017/10/31. 6 | // Copyright © 2017年 wyh. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "WyhDemoBaseCell.h" 11 | #import "WyhDemoListVC.h" 12 | 13 | @interface ViewController () 14 | 15 | @property (nonatomic, strong) NSMutableArray *sectionViewsArr; 16 | 17 | @property (nonatomic, strong) UITableView *tableView; 18 | 19 | @property (nonatomic, strong) UILabel *sectionLabel; 20 | 21 | @end 22 | 23 | @implementation ViewController 24 | 25 | - (void)viewDidLoad { 26 | [super viewDidLoad]; 27 | // Do any additional setup after loading the view, typically from a nib. 28 | self.title = @"WyhCornerRadius"; 29 | [self.view addSubview:self.tableView]; 30 | } 31 | 32 | #pragma mark - delegate 33 | 34 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 35 | return 4; 36 | } 37 | 38 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 39 | return 1; 40 | } 41 | 42 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 43 | WyhDemoBaseCellType type = indexPath.section; 44 | WyhDemoBaseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"demo"]; 45 | if (!cell) { 46 | cell = [WyhDemoBaseCell cellWithReuseIdentifier:@"demo"]; 47 | } 48 | [cell setType:type]; 49 | return cell; 50 | } 51 | 52 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 53 | if (indexPath.section == 0) { 54 | [self pushToListViewcontrollerWithType:WyhImageViewDemoType]; 55 | } 56 | } 57 | 58 | - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 59 | return self.sectionViewsArr[section]; 60 | } 61 | 62 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 63 | return DemoCellHeight; 64 | } 65 | 66 | - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { 67 | return 30; 68 | } 69 | 70 | - (void)clickSection:(UITapGestureRecognizer *)tap { 71 | UILabel *label = (UILabel *)tap.view; 72 | if ([_sectionViewsArr indexOfObject:label] == NSNotFound) { 73 | return; 74 | } 75 | NSInteger index = [_sectionViewsArr indexOfObject:label]; 76 | switch (index) { 77 | case 0: 78 | { 79 | [self pushToListViewcontrollerWithType:WyhImageViewDemoType]; 80 | } 81 | break; 82 | case 1: 83 | { 84 | 85 | } break; 86 | default: 87 | break; 88 | } 89 | } 90 | 91 | - (void)pushToListViewcontrollerWithType:(DemoListType)type { 92 | WyhDemoListVC *listVC = [[WyhDemoListVC alloc]init]; 93 | listVC.type = type; 94 | [self.navigationController pushViewController:listVC animated:YES]; 95 | } 96 | 97 | #pragma mark - Lazy 98 | 99 | - (UITableView *)tableView { 100 | if (!_tableView) { 101 | _tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:(UITableViewStylePlain)]; 102 | _tableView.delegate = self; 103 | _tableView.dataSource = self; 104 | } 105 | return _tableView; 106 | } 107 | 108 | - (NSMutableArray *)sectionViewsArr { 109 | if (!_sectionViewsArr) { 110 | _sectionViewsArr = [NSMutableArray new]; 111 | NSArray *names = @[@" UIImageView", 112 | @" UIButton(Try to click icon)", 113 | @" UILabel", 114 | @" UIView"]; 115 | for (int i = 0; i < 4; i++) { 116 | UILabel *sectionLabel = [[UILabel alloc]init]; 117 | sectionLabel.textColor = [UIColor whiteColor]; 118 | sectionLabel.backgroundColor = [UIColor grayColor]; 119 | sectionLabel.text = names[i]; 120 | UILabel *go = [[UILabel alloc]init]; 121 | go.textAlignment = NSTextAlignmentRight; 122 | if (i==0) go.text = @">"; 123 | go.textColor = [UIColor lightGrayColor]; 124 | go.frame = CGRectMake([UIScreen mainScreen].bounds.size.width - 30, 0, 20, 30); 125 | [sectionLabel addSubview:go]; 126 | 127 | UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickSection:)]; 128 | sectionLabel.userInteractionEnabled = true; 129 | [sectionLabel addGestureRecognizer:tap]; 130 | [_sectionViewsArr addObject:sectionLabel]; 131 | } 132 | } 133 | return _sectionViewsArr; 134 | } 135 | 136 | - (void)didReceiveMemoryWarning { 137 | [super didReceiveMemoryWarning]; 138 | // Dispose of any resources that can be recreated. 139 | } 140 | 141 | 142 | @end 143 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/WyhCornerRadius.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod spec lint WyhCornerRadius.podspec' to ensure this is a 3 | # valid spec and to remove all comments including this before submitting the spec. 4 | # 5 | # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html 6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | 11 | # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 12 | # 13 | # These will help people to find your library, and whilst it 14 | # can feel like a chore to fill in it's definitely to your advantage. The 15 | # summary should be tweet-length, and the description more in depth. 16 | # 17 | 18 | s.name = "WyhCornerRadius" 19 | s.version = "1.0.1" 20 | s.summary = "Quick and easy to set UIView's corner radius and border without off-screen rendering problem in GPU." 21 | 22 | # This description is used to generate tags and improve search results. 23 | # * Think: What does it do? Why did you write it? What is the focus? 24 | # * Try to keep it short, snappy and to the point. 25 | # * Write the description between the DESC delimiters below. 26 | # * Finally, don't worry about the indent, CocoaPods strips it! 27 | # s.description = <<-DESC 28 | # DESC 29 | 30 | s.homepage = "https://github.com/XiaoWuTongZhi/WyhCornerRadius" 31 | # s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif" 32 | 33 | 34 | # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 35 | # 36 | # Licensing your code is important. See http://choosealicense.com for more info. 37 | # CocoaPods will detect a license file if there is a named LICENSE* 38 | # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'. 39 | # 40 | 41 | s.license = "MIT" 42 | # s.license = { :type => "MIT", :file => "FILE_LICENSE" } 43 | 44 | 45 | # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 46 | # 47 | # Specify the authors of the library, with email addresses. Email addresses 48 | # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also 49 | # accepts just a name if you'd rather not provide an email address. 50 | # 51 | # Specify a social_media_url where others can refer to, for example a twitter 52 | # profile URL. 53 | # 54 | 55 | s.author = { "wyh" => "609223770@qq.com" } 56 | # Or just: s.author = "wyh" 57 | # s.authors = { "wyh" => "yueheng.wu@net263.com" } 58 | # s.social_media_url = "http://twitter.com/wyh" 59 | 60 | # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 61 | # 62 | # If this Pod runs only on iOS or OS X, then specify the platform and 63 | # the deployment target. You can optionally include the target after the platform. 64 | # 65 | 66 | # s.platform = :ios 67 | s.platform = :ios, "8.0" 68 | 69 | # When using multiple platforms 70 | # s.ios.deployment_target = "5.0" 71 | # s.osx.deployment_target = "10.7" 72 | # s.watchos.deployment_target = "2.0" 73 | # s.tvos.deployment_target = "9.0" 74 | 75 | 76 | # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 77 | # 78 | # Specify the location from where the source should be retrieved. 79 | # Supports git, hg, bzr, svn and HTTP. 80 | # 81 | 82 | s.source = { :git => "https://github.com/XiaoWuTongZhi/WyhCornerRadius.git", :tag => "1.0.1" } 83 | 84 | 85 | # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 86 | # 87 | # CocoaPods is smart about how it includes source code. For source files 88 | # giving a folder will include any swift, h, m, mm, c & cpp files. 89 | # For header files it will include any header in the folder. 90 | # Not including the public_header_files will make all headers public. 91 | # 92 | 93 | s.source_files = "WyhCornerRadius", "WyhCornerRadius/WyhCornerRadius/WyhCornerRadius/*.{h,m}" 94 | # s.exclude_files = "Classes/Exclude" 95 | 96 | # s.public_header_files = "Classes/**/*.h" 97 | 98 | 99 | # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 100 | # 101 | # A list of resources included with the Pod. These are copied into the 102 | # target bundle with a build phase script. Anything else will be cleaned. 103 | # You can preserve files from being cleaned, please don't preserve 104 | # non-essential files like tests, examples and documentation. 105 | # 106 | 107 | # s.resource = "icon.png" 108 | # s.resources = "Resources/*.png" 109 | 110 | # s.preserve_paths = "FilesToSave", "MoreFilesToSave" 111 | 112 | 113 | # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 114 | # 115 | # Link your library with frameworks, or libraries. Libraries do not include 116 | # the lib prefix of their name. 117 | # 118 | 119 | s.framework = "UIKit" 120 | # s.frameworks = "SomeFramework", "AnotherFramework" 121 | 122 | # s.library = "iconv" 123 | # s.libraries = "iconv", "xml2" 124 | 125 | 126 | # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 127 | # 128 | # If your library depends on compiler flags you can set them in the xcconfig hash 129 | # where they will only apply to your library. If you depend on other Podspecs 130 | # you can include multiple dependencies to ensure it works. 131 | 132 | # s.requires_arc = true 133 | 134 | # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" } 135 | # s.dependency "JSONKit", "~> 1.4" 136 | 137 | end 138 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/WyhCornerRadius/UIImage+wyhRadius.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+wyhRadius.h 3 | // WyhCornerRadius 4 | // 5 | // Created by wyh on 2017/10/31. 6 | // Copyright © 2017年 wyh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | struct WYHRadius { 12 | CGFloat topLeftRadius; 13 | CGFloat topRightRadius; 14 | CGFloat bottomLeftRadius; 15 | CGFloat bottomRightRadius; 16 | }; 17 | typedef struct WYHRadius WYHRadius; 18 | 19 | static inline WYHRadius WYHRadiusMake(CGFloat topLeftRadius, CGFloat topRightRadius, CGFloat bottomLeftRadius, CGFloat bottomRightRadius) { 20 | WYHRadius radius; 21 | radius.topLeftRadius = topLeftRadius; 22 | radius.topRightRadius = topRightRadius; 23 | radius.bottomLeftRadius = bottomLeftRadius; 24 | radius.bottomRightRadius = bottomRightRadius; 25 | return radius; 26 | } 27 | 28 | @interface UIImage (wyhRadius) 29 | 30 | + (UIImage *)wyh_imageWithColor:(UIColor *)color; 31 | 32 | + (UIImage *)wyh_getCornerImageFromCornerRadius:(CGFloat)cornerRadius 33 | Image:(UIImage *)image 34 | Size:(CGSize)size 35 | RectCornerType:(UIRectCorner)rectCornerType 36 | BorderColor:(UIColor *)borderColor 37 | BorderWidth:(CGFloat)borderWidth 38 | BackgroundColor:(UIColor *)backgroundColor; 39 | 40 | - (UIImage *)scaleToSize:(CGSize)size backgroundColor:(UIColor *)backgroundColor; 41 | 42 | 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/WyhCornerRadius/UIImage+wyhRadius.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+wyhRadius.m 3 | // WyhCornerRadius 4 | // 5 | // Created by wyh on 2017/10/31. 6 | // Copyright © 2017年 wyh. All rights reserved. 7 | // 8 | 9 | #import "UIImage+wyhRadius.h" 10 | #import 11 | @implementation UIImage (wyhRadius) 12 | 13 | 14 | + (UIImage *)wyh_getCornerImageFromCornerRadius:(CGFloat)cornerRadius 15 | Image:(UIImage *)image 16 | Size:(CGSize)size 17 | RectCornerType:(UIRectCorner)rectCornerType 18 | BorderColor:(UIColor *)borderColor 19 | BorderWidth:(CGFloat)borderWidth 20 | BackgroundColor:(UIColor *)backgroundColor { 21 | 22 | if (!backgroundColor) { 23 | backgroundColor = [UIColor whiteColor]; 24 | } 25 | if (image) { 26 | image = [image scaleToSize:CGSizeMake(size.width, size.height) backgroundColor:backgroundColor]; 27 | } else { 28 | image = [UIImage wyh_imageWithColor:backgroundColor]; 29 | } 30 | 31 | CGRect rect = CGRectMake(0, 0, size.width, size.height); 32 | CGFloat height = size.height; 33 | CGFloat width = size.width; 34 | 35 | CGFloat topLeftR = (rectCornerType & UIRectCornerTopLeft)?cornerRadius:0; 36 | CGFloat topRightR = (rectCornerType & UIRectCornerTopRight)?cornerRadius:0; 37 | CGFloat bottomLeftR = (rectCornerType & UIRectCornerBottomLeft)?cornerRadius:0; 38 | CGFloat bottomRightR = (rectCornerType & UIRectCornerBottomRight)?cornerRadius:0; 39 | WYHRadius radius = WYHRadiusMake(topLeftR, topRightR, bottomLeftR, bottomRightR); 40 | [self transformationWYHadius:radius size:size]; 41 | 42 | UIGraphicsBeginImageContextWithOptions(size, NO, UIScreen.mainScreen.scale); 43 | 44 | CGContextRef context = UIGraphicsGetCurrentContext(); 45 | CGContextScaleCTM(context, 1, -1); 46 | CGContextTranslateCTM(context, 0, -rect.size.height); 47 | 48 | UIBezierPath *path = [[UIBezierPath alloc] init]; 49 | // UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:(rectCornerType) cornerRadii:CGSizeMake(cornerRadius, cornerRadius)]; 50 | [path addArcWithCenter:CGPointMake(width - radius.topRightRadius, height - radius.topRightRadius) radius:radius.topRightRadius startAngle:0 endAngle:M_PI_2 clockwise:YES]; 51 | [path addArcWithCenter:CGPointMake(radius.topLeftRadius, height - radius.topLeftRadius) radius:radius.topLeftRadius startAngle:M_PI_2 endAngle:M_PI clockwise:YES]; 52 | [path addArcWithCenter:CGPointMake(radius.bottomLeftRadius, radius.bottomLeftRadius) radius:radius.bottomLeftRadius startAngle:M_PI endAngle:3.0 * M_PI_2 clockwise:YES]; 53 | [path addArcWithCenter:CGPointMake(width - radius.bottomRightRadius, radius.bottomRightRadius) radius:radius.bottomRightRadius startAngle:3.0 * M_PI_2 endAngle:2.0 * M_PI clockwise:YES]; 54 | 55 | [path closePath]; 56 | [path addClip]; 57 | 58 | CGContextDrawImage(context, rect, image.CGImage); 59 | 60 | if (borderWidth!=0) { 61 | path.lineWidth = borderWidth; 62 | if (!borderColor) { 63 | borderColor = [UIColor blackColor]; 64 | } 65 | [borderColor setStroke]; 66 | [path stroke]; 67 | } 68 | 69 | UIImage *currentImage = UIGraphicsGetImageFromCurrentImageContext(); 70 | UIGraphicsEndImageContext(); 71 | 72 | return currentImage; 73 | } 74 | 75 | 76 | - (UIImage *)scaleToSize:(CGSize)size 77 | backgroundColor:(UIColor *)backgroundColor { 78 | CGRect rect = CGRectMake(0, 0, size.width, size.height); 79 | UIGraphicsBeginImageContextWithOptions(size, NO, UIScreen.mainScreen.scale); 80 | CGContextRef context = UIGraphicsGetCurrentContext(); 81 | CGContextSetFillColorWithColor(context, backgroundColor.CGColor); 82 | CGContextAddRect(context, rect); 83 | CGContextDrawPath(context, kCGPathFill); 84 | [self drawInRect:rect]; 85 | UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext(); 86 | UIGraphicsEndImageContext(); 87 | return scaledImage; 88 | } 89 | 90 | + (UIImage *)wyh_imageWithColor:(UIColor *)color { 91 | CGRect rect = CGRectMake(0, 0, 1, 1); 92 | UIGraphicsBeginImageContext(rect.size); 93 | CGContextRef context = UIGraphicsGetCurrentContext(); 94 | CGContextSetFillColorWithColor(context, [color CGColor]); 95 | CGContextFillRect(context, rect); 96 | UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 97 | UIGraphicsEndImageContext(); 98 | return image; 99 | } 100 | 101 | + (WYHRadius)transformationWYHadius:(WYHRadius)radius size:(CGSize)size { 102 | radius.topLeftRadius = minimum(size.width, size.height, radius.topLeftRadius); 103 | radius.topRightRadius = minimum(size.width - radius.topLeftRadius, size.height, radius.topRightRadius); 104 | radius.bottomLeftRadius = minimum(size.width, size.height - radius.topLeftRadius, radius.bottomLeftRadius); 105 | radius.bottomRightRadius = minimum(size.width - radius.bottomLeftRadius, size.height - radius.topRightRadius, radius.bottomRightRadius); 106 | return radius; 107 | } 108 | 109 | static inline CGFloat minimum(CGFloat a, CGFloat b, CGFloat c) { 110 | CGFloat minimum = MIN(MIN(a, b), c); 111 | return MAX(minimum, 0); 112 | } 113 | @end 114 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/WyhCornerRadius/UIImageView+wyhRadius.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+wyhRadius.h 3 | // WyhCornerRadius 4 | // 5 | // Created by wyh on 2017/10/31. 6 | // Copyright © 2017年 wyh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIImageView (wyhRadius) 12 | 13 | 14 | /** 15 | 闪速创建一个圆图 16 | 17 | @return <#return value description#> 18 | */ 19 | + (instancetype)wyh_circleImageView; 20 | 21 | /** 22 | 自动设置图片的圆角 23 | 24 | @param cornerRedius <#cornerRedius description#> 25 | @param cornerType <#cornerType description#> 26 | */ 27 | - (void)wyh_autoSetImageCornerRedius:(CGFloat)cornerRedius 28 | ConrnerType:(UIRectCorner)cornerType; 29 | 30 | 31 | /** 32 | 直接设置带圆角的图片(多适用于加载本地图片的imageView) 33 | 34 | @param cornerRedius <#cornerRedius description#> 35 | @param cornerType <#cornerType description#> 36 | @param image <#image description#> 37 | */ 38 | - (void)wyh_autoSetImageCornerRedius:(CGFloat)cornerRedius 39 | ConrnerType:(UIRectCorner)cornerType 40 | Image:(UIImage *)image; 41 | 42 | /** 43 | 自动设置带边框的图片圆角 44 | 45 | @param cornerRedius <#cornerRedius description#> 46 | @param cornerType <#cornerType description#> 47 | @param borderColor <#borderColor description#> 48 | @param borderWidth <#borderWidth description#> 49 | @param image <#backgroundColor description#> 50 | */ 51 | - (void)wyh_autoSetImageCornerRedius:(CGFloat)cornerRedius 52 | ConrnerType:(UIRectCorner)cornerType 53 | BorderColor:(UIColor *)borderColor 54 | BorderWidth:(CGFloat)borderWidth 55 | Image:(UIImage *)image; 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/WyhCornerRadius/UIImageView+wyhRadius.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+wyhRadius.m 3 | // WyhCornerRadius 4 | // 5 | // Created by wyh on 2017/10/31. 6 | // Copyright © 2017年 wyh. All rights reserved. 7 | // 8 | 9 | #import "UIImageView+wyhRadius.h" 10 | #import "UIImage+wyhRadius.h" 11 | #import 12 | #import "wyhRadiusConst.h" 13 | 14 | @interface UIImageView () 15 | 16 | @property (nonatomic, assign) CGFloat wyh_cornerRadius; 17 | @property (nonatomic, assign) UIRectCorner wyh_cornerTypes; 18 | @property (nonatomic, strong) UIColor *wyh_borderColor; 19 | @property (nonatomic, assign) CGFloat wyh_borderWidth; 20 | @property (nonatomic, strong) UIColor *wyh_backgroundColor; 21 | @property (nonatomic, assign) BOOL isInitFromCircle; 22 | @property (nonatomic, assign) BOOL isAutoSet; 23 | 24 | 25 | @end 26 | 27 | @implementation UIImageView (wyhRadius) 28 | 29 | + (void)load { 30 | [self swizzleMethod]; 31 | } 32 | 33 | + (void)swizzleMethod { 34 | static dispatch_once_t onceToken; 35 | dispatch_once(&onceToken, ^{ 36 | wyh_swizzleMethod(@selector(layoutSubviews), @selector(wyh_layoutSubview)); 37 | }); 38 | } 39 | 40 | 41 | - (void)wyh_layoutSubview { 42 | [self wyh_layoutSubview]; 43 | if (self.isAutoSet) { 44 | if (self.image) { 45 | [self settingCornerImage:self.image]; 46 | } 47 | } 48 | } 49 | 50 | #pragma mark - Publick Function 51 | 52 | + (instancetype)wyh_circleImageView { 53 | UIImageView *imageView = [[UIImageView alloc]init]; 54 | imageView.isInitFromCircle = YES; 55 | imageView.isAutoSet = YES; 56 | return imageView; 57 | } 58 | 59 | - (void)wyh_autoSetImageCornerRedius:(CGFloat)cornerRedius ConrnerType:(UIRectCorner)cornerType { 60 | [self cachePropertyWithCornerRedius:cornerRedius ConrnerType:cornerType BorderColor:nil BorderWidth:0 BackgroundColor:nil]; 61 | } 62 | 63 | - (void)wyh_autoSetImageCornerRedius:(CGFloat)cornerRedius ConrnerType:(UIRectCorner)cornerType Image:(UIImage *)image { 64 | [self cachePropertyWithCornerRedius:cornerRedius ConrnerType:cornerType BorderColor:nil BorderWidth:0 BackgroundColor:nil]; 65 | if (image) { 66 | [self setImage:image]; 67 | } 68 | } 69 | 70 | - (void)wyh_autoSetImageCornerRedius:(CGFloat)cornerRedius 71 | ConrnerType:(UIRectCorner)cornerType 72 | BorderColor:(UIColor *)borderColor 73 | BorderWidth:(CGFloat)borderWidth 74 | Image:(UIImage *)image{ 75 | [self cachePropertyWithCornerRedius:cornerRedius ConrnerType:cornerType BorderColor:borderColor BorderWidth:borderWidth BackgroundColor:nil]; 76 | if (image) { 77 | [self setImage:image]; 78 | } 79 | } 80 | 81 | 82 | 83 | #pragma mark - Private Function 84 | 85 | /** 86 | cache all the properties 87 | */ 88 | - (void)cachePropertyWithCornerRedius:(CGFloat)cornerRedius 89 | ConrnerType:(UIRectCorner)cornerType 90 | BorderColor:(UIColor *)borderColor 91 | BorderWidth:(CGFloat)borderWidth 92 | BackgroundColor:(UIColor *)backgroundColor { 93 | self.wyh_cornerRadius = cornerRedius; 94 | self.wyh_cornerTypes = cornerType; 95 | self.wyh_borderColor = borderColor; 96 | self.wyh_borderWidth = borderWidth; 97 | self.wyh_backgroundColor = backgroundColor; 98 | self.isAutoSet = YES; 99 | [self setNeedsLayout]; 100 | } 101 | 102 | /** 103 | setting the final Corner Image 104 | */ 105 | - (void)settingCornerImage:(UIImage *)image{ 106 | __block CGSize _size = self.bounds.size; 107 | if (self.isInitFromCircle) { 108 | self.wyh_cornerRadius = self.bounds.size.height/2; 109 | self.wyh_cornerTypes = UIRectCornerAllCorners; 110 | self.wyh_borderWidth = 0; 111 | self.wyh_backgroundColor = nil; 112 | } 113 | wyh_async_concurrent_dispatch(^{ 114 | UIImage *finalImage = [UIImage wyh_getCornerImageFromCornerRadius:self.wyh_cornerRadius Image:image Size:_size RectCornerType:self.wyh_cornerTypes BorderColor:self.wyh_borderColor BorderWidth:self.wyh_borderWidth BackgroundColor:self.wyh_backgroundColor]; 115 | wyh_async_safe_dispatch(^{ 116 | [self setImage:finalImage]; 117 | }); 118 | }); 119 | } 120 | 121 | #pragma mark - Property 122 | 123 | - (void)setWyh_cornerRadius:(CGFloat)wyh_cornerRadius { 124 | objc_setAssociatedObject(self, @selector(wyh_cornerRadius), @(wyh_cornerRadius), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 125 | } 126 | 127 | - (CGFloat)wyh_cornerRadius{ 128 | return [objc_getAssociatedObject(self, _cmd) doubleValue]; 129 | } 130 | 131 | - (void)setWyh_cornerTypes:(UIRectCorner)wyh_cornerTypes { 132 | objc_setAssociatedObject(self, @selector(wyh_cornerTypes), @(wyh_cornerTypes), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 133 | } 134 | 135 | - (UIRectCorner)wyh_cornerTypes { 136 | return [objc_getAssociatedObject(self, _cmd) unsignedIntegerValue]; 137 | } 138 | 139 | - (void)setWyh_borderColor:(UIColor *)wyh_borderColor { 140 | objc_setAssociatedObject(self, @selector(wyh_borderColor), wyh_borderColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 141 | } 142 | 143 | - (UIColor *)wyh_borderColor { 144 | return objc_getAssociatedObject(self, _cmd); 145 | } 146 | 147 | - (void)setWyh_backgroundColor:(UIColor *)wyh_backgroundColor { 148 | objc_setAssociatedObject(self, @selector(wyh_backgroundColor), wyh_backgroundColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 149 | } 150 | 151 | - (UIColor *)wyh_backgroundColor { 152 | return objc_getAssociatedObject(self, _cmd); 153 | } 154 | 155 | - (void)setWyh_borderWidth:(CGFloat)wyh_borderWidth { 156 | objc_setAssociatedObject(self, @selector(wyh_borderWidth), @(wyh_borderWidth), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 157 | } 158 | 159 | - (CGFloat)wyh_borderWidth { 160 | return [objc_getAssociatedObject(self, _cmd) doubleValue]; 161 | } 162 | 163 | - (void)setIsAutoSet:(BOOL)isAutoSet { 164 | objc_setAssociatedObject(self, @selector(isAutoSet), @(isAutoSet), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 165 | } 166 | 167 | - (BOOL)isAutoSet { 168 | return [objc_getAssociatedObject(self, _cmd) integerValue]; 169 | } 170 | 171 | - (void)setIsInitFromCircle:(BOOL)isInitFromCircle { 172 | objc_setAssociatedObject(self, @selector(isInitFromCircle), @(isInitFromCircle), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 173 | } 174 | 175 | - (BOOL)isInitFromCircle { 176 | return [objc_getAssociatedObject(self, _cmd) integerValue]; 177 | } 178 | 179 | @end 180 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/WyhCornerRadius/UIView+wyhRadius.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+wyhRadius.h 3 | // WyhCornerRadius 4 | // 5 | // Created by wyh on 2017/10/31. 6 | // Copyright © 2017年 wyh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /** 全部属性介绍如下(#注意以下方法暂时均需要在设置view.size后方可生效) 12 | 13 | @para cornerRadius 圆角 14 | @para image 图片 15 | @para size 尺寸 16 | @para rectCornerType 要设置的圆角方向 17 | @para borderColor 边框颜色(#只有当borderWidth!=0时生效) 18 | @para borderWidth 边框宽度 19 | @para backgroundColor 控件背景颜色(#设置后请勿再设置view的backgroundColor) 20 | @para controlState 控件状态(#暂时只用于UIButton) 21 | */ 22 | 23 | @interface UIView (wyhRadius) 24 | 25 | /** 26 | 快速设置圆角方法 27 | */ 28 | - (void)wyh_CornerRadius:(CGFloat)cornerRadius 29 | RectCornerType:(UIRectCorner)rectCornerType; 30 | 31 | /** 32 | 快速设置带背景色的圆角方法 33 | */ 34 | - (void)wyh_CornerRadius:(CGFloat)cornerRadius 35 | RectCornerType:(UIRectCorner)rectCornerType 36 | BackgroundColor:(UIColor *)backgroundColor ; 37 | 38 | /** 39 | 快速设置带图片的圆角方法 40 | */ 41 | - (void)wyh_CornerRadius:(CGFloat)cornerRadius 42 | Image:(UIImage *)image 43 | RectCornerType:(UIRectCorner)rectCornerType; 44 | 45 | /** 46 | 快速设置带边框、带图片、带背景色的圆角方法 47 | */ 48 | - (void)wyh_CornerRadius:(CGFloat)cornerRadius 49 | Image:(UIImage *)image 50 | RectCornerType:(UIRectCorner)rectCornerType 51 | BorderColor:(UIColor *)borderColor 52 | BorderWidth:(CGFloat)borderWidth 53 | BackgroundColor:(UIColor *)backgroundColor; 54 | 55 | /** 56 | UIButton的圆角设置方法(#可设置不同state下的button样式) 57 | */ 58 | - (void)wyh_CornerRadius:(CGFloat)cornerRadius 59 | Image:(UIImage *)image 60 | RectCornerType:(UIRectCorner)rectCornerType 61 | BorderColor:(UIColor *)borderColor 62 | BorderWidth:(CGFloat)borderWidth 63 | BackgroundColor:(UIColor *)backgroundColor 64 | UIControlState:(UIControlState)controlState; 65 | 66 | /** 67 | 包含所有自定义样式的方法 68 | */ 69 | - (void)wyh_CornerRadius:(CGFloat)cornerRadius 70 | Image:(UIImage *)image 71 | Size:(CGSize)size 72 | RectCornerType:(UIRectCorner)rectCornerType 73 | BorderColor:(UIColor *)borderColor 74 | BorderWidth:(CGFloat)borderWidth 75 | BackgroundColor:(UIColor *)backgroundColor 76 | UIControlState:(UIControlState)controlState; 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/WyhCornerRadius/UIView+wyhRadius.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+wyhRadius.m 3 | // WyhCornerRadius 4 | // 5 | // Created by wyh on 2017/10/31. 6 | // Copyright © 2017年 wyh. All rights reserved. 7 | // 8 | 9 | #import "UIView+wyhRadius.h" 10 | #import "UIImage+wyhRadius.h" 11 | #import 12 | #import "wyhRadiusConst.h" 13 | 14 | @interface UIView () 15 | 16 | //@property (nonatomic, assign) CGFloat wyh_cornerRadius; 17 | //@property (nonatomic, assign) UIRectCorner wyh_cornerTypes; 18 | //@property (nonatomic, strong) UIColor *wyh_borderColor; 19 | //@property (nonatomic, assign) CGFloat wyh_borderWidth; 20 | //@property (nonatomic, strong) UIColor *wyh_backgroundColor; 21 | 22 | @end 23 | 24 | @implementation UIView (wyhRadius) 25 | 26 | //- (void)wyh_layoutSubviews { 27 | // [self wyh_layoutSubviews]; 28 | //} 29 | // 30 | //- (void)wyh_dealloc { 31 | // [self wyh_dealloc]; 32 | //} 33 | 34 | #pragma mark - Publick Function 35 | 36 | - (void)wyh_CornerRadius:(CGFloat)cornerRadius 37 | RectCornerType:(UIRectCorner)rectCornerType { 38 | [self wyh_setCornerRadius:cornerRadius Image:nil Size:self.bounds.size RectCornerType:rectCornerType BorderColor:nil BorderWidth:0 BackgroundColor:nil]; 39 | } 40 | 41 | - (void)wyh_CornerRadius:(CGFloat)cornerRadius 42 | RectCornerType:(UIRectCorner)rectCornerType 43 | BackgroundColor:(UIColor *)backgroundColor { 44 | [self wyh_setCornerRadius:cornerRadius Image:nil Size:self.bounds.size RectCornerType:rectCornerType BorderColor:nil BorderWidth:0 BackgroundColor:backgroundColor]; 45 | } 46 | 47 | - (void)wyh_CornerRadius:(CGFloat)cornerRadius 48 | Image:(UIImage *)image 49 | RectCornerType:(UIRectCorner)rectCornerType { 50 | [self wyh_setCornerRadius:cornerRadius Image:image Size:self.bounds.size RectCornerType:rectCornerType BorderColor:nil BorderWidth:0 BackgroundColor:nil]; 51 | } 52 | 53 | - (void)wyh_CornerRadius:(CGFloat)cornerRadius 54 | Image:(UIImage *)image 55 | RectCornerType:(UIRectCorner)rectCornerType 56 | BorderColor:(UIColor *)borderColor 57 | BorderWidth:(CGFloat)borderWidth 58 | BackgroundColor:(UIColor *)backgroundColor { 59 | [self wyh_setCornerRadius:cornerRadius Image:image Size:self.bounds.size RectCornerType:rectCornerType BorderColor:borderColor BorderWidth:borderWidth BackgroundColor:backgroundColor]; 60 | } 61 | 62 | - (void)wyh_CornerRadius:(CGFloat)cornerRadius 63 | Image:(UIImage *)image 64 | RectCornerType:(UIRectCorner)rectCornerType 65 | BorderColor:(UIColor *)borderColor 66 | BorderWidth:(CGFloat)borderWidth 67 | BackgroundColor:(UIColor *)backgroundColor 68 | UIControlState:(UIControlState)controlState { 69 | [self wyh_setCornerRadius:cornerRadius Image:image Size:self.bounds.size RectCornerType:rectCornerType BorderColor:borderColor BorderWidth:borderWidth BackgroundColor:backgroundColor UIControlState:(controlState)]; 70 | } 71 | 72 | - (void)wyh_CornerRadius:(CGFloat)cornerRadius 73 | Image:(UIImage *)image 74 | Size:(CGSize)size 75 | RectCornerType:(UIRectCorner)rectCornerType 76 | BorderColor:(UIColor *)borderColor 77 | BorderWidth:(CGFloat)borderWidth 78 | BackgroundColor:(UIColor *)backgroundColor 79 | UIControlState:(UIControlState)controlState { 80 | [self wyh_setCornerRadius:cornerRadius Image:image Size:size RectCornerType:rectCornerType BorderColor:borderColor BorderWidth:borderWidth BackgroundColor:backgroundColor UIControlState:(controlState)]; 81 | } 82 | 83 | #pragma mark - Private Fuction 84 | 85 | - (void)wyh_setCornerRadius:(CGFloat)cornerRadius 86 | Image:(UIImage *)image 87 | Size:(CGSize)size 88 | RectCornerType:(UIRectCorner)rectCornerType 89 | BorderColor:(UIColor *)borderColor 90 | BorderWidth:(CGFloat)borderWidth 91 | BackgroundColor:(UIColor *)backgroundColor { 92 | [self wyh_setCornerRadius:cornerRadius Image:image Size:size RectCornerType:rectCornerType BorderColor:borderColor BorderWidth:borderWidth BackgroundColor:backgroundColor UIControlState:(UIControlStateNormal)]; 93 | } 94 | 95 | - (void)wyh_setCornerRadius:(CGFloat)cornerRadius 96 | Image:(UIImage *)image 97 | Size:(CGSize)size 98 | RectCornerType:(UIRectCorner)rectCornerType 99 | BorderColor:(UIColor *)borderColor 100 | BorderWidth:(CGFloat)borderWidth 101 | BackgroundColor:(UIColor *)backgroundColor 102 | UIControlState:(UIControlState)controlState{ 103 | 104 | // self.wyh_cornerRadius = cornerRadius; 105 | // self.wyh_cornerTypes = rectCornerType; 106 | // self.wyh_borderColor = borderColor; 107 | // self.wyh_borderWidth = borderWidth; 108 | // self.wyh_backgroundColor = backgroundColor; 109 | 110 | __block CGSize _size = size; 111 | 112 | __weak typeof(self) weakSelf = self; 113 | wyh_async_concurrent_dispatch(^{ 114 | 115 | if (CGSizeEqualToSize(_size, CGSizeZero)) { 116 | if (CGSizeEqualToSize(weakSelf.bounds.size, CGSizeZero)) { 117 | return ; 118 | } 119 | wyh_async_safe_dispatch(^{ 120 | _size = weakSelf.bounds.size; 121 | }); 122 | } 123 | UIImage *currentImage = [UIImage wyh_getCornerImageFromCornerRadius:cornerRadius Image:image Size:_size RectCornerType:rectCornerType BorderColor:borderColor BorderWidth:borderWidth BackgroundColor:backgroundColor]; 124 | 125 | wyh_async_safe_dispatch(^{ 126 | if ([self isKindOfClass:[UIImageView class]]) { 127 | ((UIImageView *)self).image = currentImage; 128 | } else if ([self isKindOfClass:[UIButton class]]) { 129 | [((UIButton *)self) setBackgroundImage:currentImage forState:controlState]; 130 | } else if ([self isKindOfClass:[UILabel class]]) { 131 | self.layer.backgroundColor = [UIColor colorWithPatternImage:currentImage].CGColor; //Mark a memory problem 132 | 133 | } else { 134 | self.layer.contents = (__bridge id _Nullable)(currentImage.CGImage); 135 | } 136 | }); 137 | }); 138 | 139 | } 140 | 141 | #pragma mark - Property 142 | 143 | //- (void)setIsHadAddObserver:(BOOL)isHadAddObserver { 144 | // objc_setAssociatedObject(self, @selector(isHadAddObserver), @(isHadAddObserver), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 145 | //} 146 | // 147 | //- (BOOL)isHadAddObserver { 148 | // return [objc_getAssociatedObject(self, _cmd) boolValue]; 149 | //} 150 | // 151 | //- (void)setWyh_cornerRadius:(CGFloat)wyh_cornerRadius { 152 | // objc_setAssociatedObject(self, @selector(wyh_cornerRadius), @(wyh_cornerRadius), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 153 | //} 154 | // 155 | //- (CGFloat)wyh_cornerRadius{ 156 | // return [objc_getAssociatedObject(self, _cmd) doubleValue]; 157 | //} 158 | // 159 | //- (void)setWyh_cornerTypes:(UIRectCorner)wyh_cornerTypes { 160 | // objc_setAssociatedObject(self, @selector(wyh_cornerTypes), @(wyh_cornerTypes), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 161 | //} 162 | // 163 | //- (UIRectCorner)wyh_cornerTypes { 164 | // return [objc_getAssociatedObject(self, _cmd) unsignedIntegerValue]; 165 | //} 166 | // 167 | //- (void)setWyh_borderColor:(UIColor *)wyh_borderColor { 168 | // objc_setAssociatedObject(self, @selector(wyh_borderColor), wyh_borderColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 169 | //} 170 | // 171 | //- (UIColor *)wyh_borderColor { 172 | // return objc_getAssociatedObject(self, _cmd); 173 | //} 174 | // 175 | //- (void)setWyh_backgroundColor:(UIColor *)wyh_backgroundColor { 176 | // objc_setAssociatedObject(self, @selector(wyh_backgroundColor), wyh_backgroundColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 177 | //} 178 | // 179 | //- (UIColor *)wyh_backgroundColor { 180 | // return objc_getAssociatedObject(self, _cmd); 181 | //} 182 | // 183 | //- (void)setWyh_borderWidth:(CGFloat)wyh_borderWidth { 184 | // objc_setAssociatedObject(self, @selector(wyh_borderWidth), @(wyh_borderWidth), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 185 | //} 186 | // 187 | //- (CGFloat)wyh_borderWidth { 188 | // return [objc_getAssociatedObject(self, _cmd) doubleValue]; 189 | //} 190 | 191 | @end 192 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/WyhCornerRadius/wyhCornerRadius.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #import "UIImageView+wyhRadius.h" 5 | #import "UIView+wyhRadius.h" 6 | #import "UIImage+wyhRadius.h" 7 | 8 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/WyhCornerRadius/wyhRadiusConst.h: -------------------------------------------------------------------------------- 1 | // 2 | // wyhRadiusConst.h 3 | // WyhCornerRadius 4 | // 5 | // Created by wyh on 2017/10/31. 6 | // Copyright © 2017年 wyh. All rights reserved. 7 | // 8 | 9 | #ifndef wyhRadiusConst_h 10 | #define wyhRadiusConst_h 11 | 12 | #define wyh_swizzleMethod(oneSel,anotherSel) \ 13 | Method oneMethod = class_getInstanceMethod(self, oneSel); \ 14 | Method anotherMethod = class_getInstanceMethod(self, anotherSel); \ 15 | method_exchangeImplementations(oneMethod, anotherMethod); \ 16 | 17 | #define wyh_async_concurrent_dispatch(block) dispatch_async(dispatch_queue_create("WyhDrawingImage", DISPATCH_QUEUE_CONCURRENT),block); 18 | 19 | #define wyh_async_safe_dispatch(block) \ 20 | if ([NSThread isMainThread]) { \ 21 | block(); \ 22 | } else { \ 23 | dispatch_async(dispatch_get_main_queue(), block); \ 24 | } 25 | 26 | #endif /* wyhRadiusConst_h */ 27 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/WyhDemoBaseCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // WyhDemoBaseCell.h 3 | // WyhCornerRadius 4 | // 5 | // Created by wyh on 2017/11/1. 6 | // Copyright © 2017年 wyh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | static CGFloat const DemoCellHeight = 100; 12 | 13 | typedef NS_ENUM(NSInteger,WyhDemoBaseCellType) { 14 | WYHImageViewType = 0, 15 | WYHButtonType = 1, 16 | WYHLabelType = 2, 17 | WYHViewElseType = 3, 18 | }; 19 | 20 | @interface WyhDemoBaseCell : UITableViewCell 21 | 22 | + (instancetype)cellWithReuseIdentifier:(NSString *)reuseIdentifier; 23 | 24 | @property (nonatomic, assign) WyhDemoBaseCellType type; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/WyhDemoBaseCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // WyhDemoBaseCell.m 3 | // WyhCornerRadius 4 | // 5 | // Created by wyh on 2017/11/1. 6 | // Copyright © 2017年 wyh. All rights reserved. 7 | // 8 | 9 | #import "WyhDemoBaseCell.h" 10 | #import "wyhCornerRadius.h" 11 | 12 | #define kWidth [UIScreen mainScreen].bounds.size.width 13 | #define kHeight [UIScreen mainScreen].bounds.size.height 14 | #define Space 10 15 | #define viewWidth ((kWidth - 6*Space)/5) 16 | 17 | @interface WyhDemoBaseCell() 18 | 19 | @property (nonatomic, strong) NSMutableArray *views; 20 | 21 | @end 22 | 23 | @implementation WyhDemoBaseCell 24 | 25 | - (void)awakeFromNib { 26 | [super awakeFromNib]; 27 | // Initialization code 28 | } 29 | 30 | + (instancetype)cellWithReuseIdentifier:(NSString *)reuseIdentifier{ 31 | WyhDemoBaseCell *cell = [[WyhDemoBaseCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"demo"]; 32 | return cell; 33 | } 34 | 35 | - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 36 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 37 | if (self) { 38 | self.selectionStyle = 0; 39 | } 40 | return self; 41 | } 42 | 43 | - (void)setType:(WyhDemoBaseCellType)type { 44 | [self createViewsWithType:type]; 45 | } 46 | 47 | - (void)createViewsWithType:(WyhDemoBaseCellType)type { 48 | 49 | for (int i = 0; i < 5; i++) { 50 | switch (type) { 51 | case WYHImageViewType: 52 | { 53 | UIImageView *img = [self createImageViewWithIndex:i]; 54 | [self.views addObject:img]; 55 | } break; 56 | case WYHButtonType: 57 | { 58 | UIButton *button = [self createButtonWithIndex:i]; 59 | [self.views addObject:button]; 60 | } break; 61 | case WYHLabelType: 62 | { 63 | UILabel *label = [self createLabelWithIndex:i]; 64 | [self.views addObject:label]; 65 | } break; 66 | case WYHViewElseType: 67 | { 68 | UIView *view = [self createViewWithIndex:i]; 69 | [self.views addObject:view]; 70 | } break; 71 | default: break; 72 | } 73 | } 74 | 75 | [self.views enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { 76 | [self.contentView addSubview:(UIView *)obj]; 77 | }]; 78 | } 79 | 80 | #pragma mark - UIImageView 81 | 82 | - (UIImageView *)createImageViewWithIndex:(NSInteger)index { 83 | UIImageView *img = [[UIImageView alloc]init]; 84 | img.frame = [self configFrameWithIndex:index]; 85 | UIRectCorner rectCorner = [self configRectCornerWithIndex:index]; 86 | [img wyh_autoSetImageCornerRedius:viewWidth/2 ConrnerType:rectCorner Image:[UIImage imageNamed:[NSString stringWithFormat:@"dog%ld",index+1]]]; 87 | return img; 88 | } 89 | 90 | #pragma mark - UIButton 91 | 92 | - (UIButton *)createButtonWithIndex:(NSInteger)index { 93 | UIImage *imageNormal = [UIImage imageNamed:[NSString stringWithFormat:@"dog%ld",index+1]]; 94 | UIImage *imageSelected = [UIImage imageNamed:[NSString stringWithFormat:@"dog%ld",(index!=2)?(5-index):1]]; 95 | UIButton *btn = [UIButton buttonWithType:(UIButtonTypeCustom)]; 96 | btn.frame = [self configFrameWithIndex:index]; 97 | [btn addTarget:self action:@selector(btnClickAction:) forControlEvents:(UIControlEventTouchUpInside)]; 98 | //设置button的normal状态图片 99 | [btn wyh_CornerRadius:viewWidth/2 Image:imageNormal RectCornerType:[self configRectCornerWithIndex:index] BorderColor:[UIColor blueColor] BorderWidth:3 BackgroundColor:nil UIControlState:(UIControlStateNormal)]; 100 | //设置button的selected状态图片 101 | [btn wyh_CornerRadius:viewWidth/2 Image:imageSelected RectCornerType:[self configRectCornerWithIndex:index] BorderColor:[UIColor redColor] BorderWidth:3 BackgroundColor:nil UIControlState:(UIControlStateSelected)]; 102 | return btn; 103 | } 104 | 105 | #pragma mark - UILabel 106 | 107 | - (UILabel *)createLabelWithIndex:(NSInteger)index { 108 | UILabel *label = [[UILabel alloc]init]; 109 | label.text = [NSString stringWithFormat:@"%ld",index+1]; 110 | label.textAlignment = NSTextAlignmentCenter; 111 | label.frame = [self configFrameWithIndex:index]; 112 | UIRectCorner rectCorner = [self configRectCornerWithIndex:index]; 113 | [label wyh_CornerRadius:viewWidth/2 Image:nil RectCornerType:rectCorner BorderColor:[UIColor magentaColor] BorderWidth:2 BackgroundColor:nil]; 114 | return label; 115 | } 116 | 117 | #pragma mark - UIView 118 | 119 | - (UIView *)createViewWithIndex:(NSInteger)index { 120 | UIView *view = [[UIView alloc]init]; 121 | view.frame = [self configFrameWithIndex:index]; 122 | UIRectCorner rectCorner = [self configRectCornerWithIndex:index]; 123 | UIColor *randomColor = [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]; 124 | [view wyh_CornerRadius:viewWidth/2 RectCornerType:rectCorner BackgroundColor:randomColor]; 125 | return view; 126 | } 127 | 128 | - (UIRectCorner)configRectCornerWithIndex:(NSInteger)index { 129 | UIRectCorner rectCorner; 130 | switch (index) { 131 | case 0: 132 | rectCorner = UIRectCornerTopLeft; break; 133 | case 1: 134 | rectCorner = UIRectCornerTopRight; break; 135 | case 2: 136 | rectCorner = UIRectCornerBottomLeft; break; 137 | case 3: 138 | rectCorner = UIRectCornerBottomRight; break; 139 | default: 140 | rectCorner = UIRectCornerAllCorners; break; 141 | } 142 | return rectCorner; 143 | } 144 | 145 | - (CGRect)configFrameWithIndex:(NSInteger)index { 146 | CGRect rect = CGRectZero; 147 | return rect = CGRectMake(Space+index*(Space+viewWidth), (DemoCellHeight - viewWidth)/2, viewWidth, viewWidth); 148 | } 149 | 150 | - (void)btnClickAction:(UIButton *)sender { 151 | sender.selected = !sender.selected; 152 | } 153 | 154 | #pragma mark - lazy 155 | 156 | - (NSMutableArray *)views { 157 | if (!_views) { 158 | _views = [NSMutableArray new]; 159 | } 160 | return _views; 161 | } 162 | 163 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated { 164 | [super setSelected:selected animated:animated]; 165 | 166 | // Configure the view for the selected state 167 | } 168 | 169 | @end 170 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/WyhDemoListVC/WyhDemoBaseVC.h: -------------------------------------------------------------------------------- 1 | // 2 | // WyhDemoBaseVC.h 3 | // WyhCornerRadius 4 | // 5 | // Created by wyh on 2017/11/1. 6 | // Copyright © 2017年 wyh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface WyhDemoBaseVC : UIViewController 12 | 13 | @property (nonatomic, strong) UITableView *tableView; 14 | @property (nonatomic, strong) UITableView *offTableView; 15 | 16 | @property (nonatomic, strong) NSMutableArray *dataSource; 17 | @property (nonatomic, assign) BOOL isOff_ScreenRender; 18 | 19 | 20 | //- (void)changeRenderingMode; 21 | 22 | - (void)changeRenderingModeFromSubClass; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/WyhDemoListVC/WyhDemoBaseVC.m: -------------------------------------------------------------------------------- 1 | // 2 | // WyhDemoBaseVC.m 3 | // WyhCornerRadius 4 | // 5 | // Created by wyh on 2017/11/1. 6 | // Copyright © 2017年 wyh. All rights reserved. 7 | // 8 | 9 | #import "WyhDemoBaseVC.h" 10 | 11 | @interface WyhDemoBaseVC () 12 | 13 | @end 14 | 15 | @implementation WyhDemoBaseVC 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | // Do any additional setup after loading the view. 20 | 21 | 22 | [self.view addSubview:self.tableView]; 23 | [self.view addSubview:self.offTableView]; 24 | 25 | self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"normalModel" style:(UIBarButtonItemStylePlain) target:self action:@selector(changeRenderingMode:)]; 26 | 27 | } 28 | 29 | - (void)changeRenderingMode:(UIBarButtonItem *)barItem{ 30 | self.isOff_ScreenRender = !self.isOff_ScreenRender; 31 | self.offTableView.hidden = !self.isOff_ScreenRender; 32 | self.tableView.hidden = self.isOff_ScreenRender; 33 | if (self.isOff_ScreenRender) { 34 | [barItem setTitle:@"off-sModel"]; 35 | [barItem setTintColor:[UIColor redColor]]; 36 | }else { 37 | [barItem setTitle:@"normalModel"]; 38 | [barItem setTintColor:[UIColor blueColor]]; 39 | } 40 | [self changeRenderingModeFromSubClass]; 41 | } 42 | 43 | - (void)changeRenderingModeFromSubClass { 44 | // subClass implementation 45 | } 46 | 47 | #pragma mark - Lazy 48 | 49 | -(UITableView *)tableView{ 50 | if (!_tableView) { 51 | _tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:(UITableViewStylePlain)]; 52 | } 53 | return _tableView; 54 | } 55 | 56 | - (UITableView *)offTableView { 57 | if (!_offTableView) { 58 | _offTableView = [[UITableView alloc]initWithFrame:self.view.bounds style:(UITableViewStylePlain)]; 59 | _offTableView.hidden = YES; 60 | } 61 | return _offTableView; 62 | } 63 | 64 | - (NSMutableArray *)dataSource { 65 | if (!_dataSource) { 66 | _dataSource = [NSMutableArray new]; 67 | } 68 | return _dataSource; 69 | } 70 | 71 | - (void)didReceiveMemoryWarning { 72 | [super didReceiveMemoryWarning]; 73 | // Dispose of any resources that can be recreated. 74 | } 75 | 76 | /* 77 | #pragma mark - Navigation 78 | 79 | // In a storyboard-based application, you will often want to do a little preparation before navigation 80 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 81 | // Get the new view controller using [segue destinationViewController]. 82 | // Pass the selected object to the new view controller. 83 | } 84 | */ 85 | 86 | @end 87 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/WyhDemoListVC/WyhDemoListVC.h: -------------------------------------------------------------------------------- 1 | // 2 | // WyhDemoListVC.h 3 | // WyhCornerRadius 4 | // 5 | // Created by wyh on 2017/11/3. 6 | // Copyright © 2017年 wyh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef NS_ENUM(NSInteger, DemoListType) { 12 | WyhImageViewDemoType = 0, 13 | WyhButtomDemoType , 14 | WyhLabelDemoType , 15 | WyhViewDemoType , 16 | }; 17 | 18 | @interface WyhDemoListVC : UIViewController 19 | 20 | @property (nonatomic, assign) DemoListType type; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/WyhDemoListVC/WyhDemoListVC.m: -------------------------------------------------------------------------------- 1 | // 2 | // WyhDemoListVC.m 3 | // WyhCornerRadius 4 | // 5 | // Created by wyh on 2017/11/3. 6 | // Copyright © 2017年 wyh. All rights reserved. 7 | // 8 | 9 | #import "WyhDemoListVC.h" 10 | #import "WyhImageViewDemoVC.h" 11 | 12 | @interface WyhDemoListVC () 13 | 14 | @property (nonatomic, strong) UITableView *tableView; 15 | 16 | @property (nonatomic, strong) NSArray *dataSource; 17 | 18 | @end 19 | 20 | @implementation WyhDemoListVC 21 | 22 | - (void)viewDidLoad { 23 | [super viewDidLoad]; 24 | 25 | [self.view addSubview:self.tableView]; 26 | 27 | //set the data titles 28 | switch (self.type) { 29 | case WyhImageViewDemoType: 30 | self.dataSource = @[@"网络图片测试", 31 | @"本地图片测试"]; 32 | break; 33 | default: 34 | break; 35 | } 36 | 37 | } 38 | 39 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 40 | return self.dataSource.count; 41 | } 42 | 43 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 44 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; 45 | if (!cell) { 46 | cell = [[UITableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"cell"]; 47 | cell.textLabel.text = self.dataSource[indexPath.row]; 48 | } 49 | return cell; 50 | } 51 | 52 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 53 | switch (self.type) { 54 | case WyhImageViewDemoType: 55 | { 56 | WyhImageViewDemoVC *demo = [[WyhImageViewDemoVC alloc]init]; 57 | if (indexPath.row == 0) { 58 | demo.isNeedRequestServer = YES; 59 | }else { 60 | demo.isNeedRequestServer = NO; 61 | } 62 | [self.navigationController pushViewController:demo animated:YES]; 63 | break; 64 | } 65 | default: 66 | break; 67 | } 68 | } 69 | 70 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 71 | return 50; 72 | } 73 | 74 | - (UITableView *)tableView { 75 | if (!_tableView) { 76 | _tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:(UITableViewStyleGrouped)]; 77 | _tableView.delegate = self; 78 | _tableView.dataSource = self; 79 | } 80 | return _tableView; 81 | } 82 | 83 | /* 84 | #pragma mark - Navigation 85 | 86 | // In a storyboard-based application, you will often want to do a little preparation before navigation 87 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 88 | // Get the new view controller using [segue destinationViewController]. 89 | // Pass the selected object to the new view controller. 90 | } 91 | */ 92 | 93 | @end 94 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/WyhDemoListVC/WyhImageViewDemo/WyhImageViewDemoCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // WyhImageViewDemoCell.h 3 | // WyhCornerRadius 4 | // 5 | // Created by wyh on 2017/11/1. 6 | // Copyright © 2017年 wyh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | static CGFloat const DemoCellHeight = 90; 12 | 13 | @interface WyhImageViewDemoCell : UITableViewCell 14 | 15 | +(instancetype)cellWithReuseIdentifier:(NSString *)reuseIdentifier off_scMode:(BOOL)isOff_sc; 16 | 17 | - (void)setUrlArr:(NSArray *)urls; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/WyhDemoListVC/WyhImageViewDemo/WyhImageViewDemoCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // WyhImageViewDemoCell.m 3 | // WyhCornerRadius 4 | // 5 | // Created by wyh on 2017/11/1. 6 | // Copyright © 2017年 wyh. All rights reserved. 7 | // 8 | 9 | #import "WyhImageViewDemoCell.h" 10 | #import "wyhCornerRadius.h" 11 | #import "UIImageView+WebCache.h" 12 | 13 | #define Space 10 14 | #define viewWidth ((kWidth - 6*Space)/5) 15 | #define kWidth [UIScreen mainScreen].bounds.size.width 16 | #define kHeight [UIScreen mainScreen].bounds.size.height 17 | 18 | 19 | @interface WyhImageViewDemoCell () 20 | 21 | @property (nonatomic, strong) NSMutableArray *ImageViews; 22 | @property (nonatomic, assign) BOOL isOffscreen; 23 | 24 | @end 25 | 26 | @implementation WyhImageViewDemoCell 27 | 28 | - (void)awakeFromNib { 29 | [super awakeFromNib]; 30 | // Initialization code 31 | } 32 | 33 | +(instancetype)cellWithReuseIdentifier:(NSString *)reuseIdentifier off_scMode:(BOOL)isOff_sc { 34 | WyhImageViewDemoCell *cell = [[WyhImageViewDemoCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:reuseIdentifier]; 35 | cell.isOffscreen = isOff_sc; 36 | [cell createImageViews]; 37 | return cell; 38 | } 39 | 40 | - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 41 | if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { 42 | 43 | } 44 | return self; 45 | } 46 | 47 | - (void)createImageViews{ 48 | 49 | for (int index = 0; index < 5; index++) { 50 | UIImageView *img = [[UIImageView alloc]init]; 51 | 52 | img.frame = [self configFrameWithIndex:index]; 53 | if (!self.isOffscreen) { 54 | 55 | [img wyh_autoSetImageCornerRedius:viewWidth/2 ConrnerType:(UIRectCornerAllCorners) BorderColor:[UIColor greenColor] BorderWidth:1 Image:nil]; 56 | }else { 57 | img.layer.borderColor = [UIColor redColor].CGColor; 58 | img.layer.borderWidth = 1; 59 | img.layer.masksToBounds = YES; 60 | img.layer.cornerRadius = viewWidth/2; 61 | } 62 | [self.ImageViews addObject:img]; 63 | [self.contentView addSubview:img]; 64 | } 65 | } 66 | 67 | - (CGRect)configFrameWithIndex:(NSInteger)index { 68 | CGRect rect = CGRectZero; 69 | return rect = CGRectMake(Space+index*(Space+viewWidth), (DemoCellHeight - viewWidth)/2, viewWidth, viewWidth); 70 | } 71 | 72 | - (void)setUrlArr:(NSArray *)urls { 73 | [self.ImageViews enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { 74 | UIImageView *img = (UIImageView *)obj; 75 | if ([urls[0] isKindOfClass:[NSURL class]]) { 76 | [img sd_setImageWithURL:urls[idx] placeholderImage:[UIImage imageNamed:@"glb_placeholder"]]; 77 | 78 | }else { 79 | [img wyh_autoSetImageCornerRedius:viewWidth/2 ConrnerType:(UIRectCornerAllCorners) BorderColor:[UIColor greenColor] BorderWidth:1 Image:[UIImage imageNamed:urls[idx]]]; 80 | } 81 | }]; 82 | } 83 | 84 | - (NSMutableArray *)ImageViews { 85 | if (!_ImageViews) { 86 | _ImageViews = [NSMutableArray new]; 87 | } 88 | return _ImageViews; 89 | } 90 | 91 | 92 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated { 93 | [super setSelected:selected animated:animated]; 94 | 95 | // Configure the view for the selected state 96 | } 97 | 98 | @end 99 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/WyhDemoListVC/WyhImageViewDemo/WyhImageViewDemoVC.h: -------------------------------------------------------------------------------- 1 | // 2 | // WyhImageViewDemoVC.h 3 | // WyhCornerRadius 4 | // 5 | // Created by wyh on 2017/11/1. 6 | // Copyright © 2017年 wyh. All rights reserved. 7 | // 8 | 9 | #import "WyhDemoBaseVC.h" 10 | 11 | @interface WyhImageViewDemoVC : WyhDemoBaseVC 12 | 13 | @property (nonatomic, assign) BOOL isNeedRequestServer; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/WyhDemoListVC/WyhImageViewDemo/WyhImageViewDemoVC.m: -------------------------------------------------------------------------------- 1 | // 2 | // WyhImageViewDemoVC.m 3 | // WyhCornerRadius 4 | // 5 | // Created by wyh on 2017/11/1. 6 | // Copyright © 2017年 wyh. All rights reserved. 7 | // 8 | 9 | #import "WyhImageViewDemoVC.h" 10 | 11 | #import "WyhImageViewDemoCell.h" 12 | 13 | @interface WyhImageViewDemoVC () 14 | 15 | @property (nonatomic, strong) NSMutableArray *serverImageUrls; 16 | @property (nonatomic, strong) NSMutableArray *localImageUrls; 17 | 18 | 19 | @end 20 | 21 | @implementation WyhImageViewDemoVC 22 | 23 | - (void)viewDidLoad { 24 | [super viewDidLoad]; 25 | // Do any additional setup after loading the view. 26 | 27 | self.title = (self.isNeedRequestServer)?@"set URL image":@"set local image"; 28 | 29 | self.tableView.delegate = self; 30 | self.tableView.dataSource = self; 31 | self.offTableView.delegate = self; 32 | self.offTableView.dataSource = self; 33 | 34 | for (int i = 0; i < 100; i++) { 35 | @autoreleasepool { 36 | NSNumber *index = @(i); 37 | [self.dataSource addObject:index]; 38 | } 39 | } 40 | 41 | // [self.tableView reloadData]; 42 | } 43 | 44 | - (void)changeRenderingModeFromSubClass { 45 | 46 | } 47 | 48 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 49 | return DemoCellHeight; 50 | } 51 | 52 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 53 | return self.dataSource.count; 54 | } 55 | 56 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 57 | NSString *reuseID; 58 | BOOL off_sc = NO; 59 | if ([tableView isEqual:self.tableView]) { 60 | reuseID = @"_WyhImageViewDemoCell"; 61 | off_sc = NO; 62 | }else { 63 | reuseID = @"WyhImageViewDemoCell"; 64 | off_sc = YES; 65 | } 66 | WyhImageViewDemoCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseID]; 67 | if (!cell) { 68 | cell = [WyhImageViewDemoCell cellWithReuseIdentifier:reuseID off_scMode:off_sc]; 69 | } 70 | NSArray *dataArr ; 71 | if (self.isNeedRequestServer) { 72 | dataArr = [self serverImageUrlsFromRandomRange]; 73 | }else { 74 | dataArr = [self localImageNamesFromRandomRange]; 75 | } 76 | [cell setUrlArr:dataArr]; 77 | 78 | return cell; 79 | } 80 | 81 | - (NSArray *)serverImageUrlsFromRandomRange{ 82 | int random = 0+arc4random()%(20+1); 83 | return [self.serverImageUrls subarrayWithRange:NSMakeRange(random, 5)]; 84 | } 85 | 86 | - (NSArray *)localImageNamesFromRandomRange{ 87 | int random = 0+arc4random()%(5+1); 88 | return [self.localImageUrls subarrayWithRange:NSMakeRange(random, 5)]; 89 | } 90 | 91 | - (NSMutableArray *)serverImageUrls { 92 | if (!_serverImageUrls) { 93 | _serverImageUrls = [NSMutableArray new]; 94 | for (int i = 0; i < 25; i++) { 95 | // NSString *str = [NSString stringWithFormat:@"http://t1.mmonly.cc/uploads/tu/bj/tp/032/%d.jpg",i+1]; //Invalid url. 96 | NSString *str = [NSString stringWithFormat:@"http://upload-images.jianshu.io/upload_images/4097230-586b3d9f46dc5a18.jpg?imageMogr2/auto-orient/strip%@7CimageView2/2/w/1240",@"%"]; 97 | // NSLog(@"%@",str); 98 | NSURL *url = [NSURL URLWithString:str]; 99 | [_serverImageUrls addObject:url]; 100 | } 101 | } 102 | return _serverImageUrls; 103 | } 104 | 105 | - (NSMutableArray *)localImageUrls { 106 | if (!_localImageUrls) { 107 | _localImageUrls = [NSMutableArray new]; 108 | for (int i = 0; i < 10; i++) { 109 | NSString *name = [NSString stringWithFormat:@"local%d",i+1]; 110 | [_localImageUrls addObject:name]; 111 | } 112 | } 113 | return _localImageUrls; 114 | } 115 | 116 | - (void)didReceiveMemoryWarning { 117 | [super didReceiveMemoryWarning]; 118 | // Dispose of any resources that can be recreated. 119 | } 120 | 121 | /* 122 | #pragma mark - Navigation 123 | 124 | // In a storyboard-based application, you will often want to do a little preparation before navigation 125 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 126 | // Get the new view controller using [segue destinationViewController]. 127 | // Pass the selected object to the new view controller. 128 | } 129 | */ 130 | 131 | @end 132 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadius/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // WyhCornerRadius 4 | // 5 | // Created by wyh on 2017/10/31. 6 | // Copyright © 2017年 wyh. 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 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadiusTests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadiusTests/WyhCornerRadiusTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // WyhCornerRadiusTests.m 3 | // WyhCornerRadiusTests 4 | // 5 | // Created by wyh on 2017/10/31. 6 | // Copyright © 2017年 wyh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface WyhCornerRadiusTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation WyhCornerRadiusTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadiusUITests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /WyhCornerRadius/WyhCornerRadiusUITests/WyhCornerRadiusUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // WyhCornerRadiusUITests.m 3 | // WyhCornerRadiusUITests 4 | // 5 | // Created by wyh on 2017/10/31. 6 | // Copyright © 2017年 wyh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface WyhCornerRadiusUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation WyhCornerRadiusUITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | --------------------------------------------------------------------------------