├── .gitignore ├── LICENSE ├── README.md ├── TKRoundedView.h ├── TKRoundedView.m ├── TKRoundedView.podspec ├── TKRoundedView.xcodeproj └── project.pbxproj └── TKRoundedView ├── Default-568h@2x.png ├── Default.png ├── Default@2x.png ├── TKAppDelegate.h ├── TKAppDelegate.m ├── TKRoundedView-Info.plist ├── TKRoundedView-Prefix.pch ├── TKViewController.h ├── TKViewController.m ├── en.lproj └── InfoPlist.strings └── main.m /.gitignore: -------------------------------------------------------------------------------- 1 | TKRoundedView.xcodeproj/project.xcworkspace/contents.xcworkspacedata 2 | TKRoundedView.xcodeproj/project.xcworkspace/xcuserdata/mapedd.xcuserdatad/UserInterfaceState.xcuserstate 3 | TKRoundedView.xcodeproj/xcuserdata/mapedd.xcuserdatad/xcschemes/TKRoundedView.xcscheme 4 | TKRoundedView.xcodeproj/xcuserdata/mapedd.xcuserdatad/xcschemes/xcschememanagement.plist 5 | TKRoundedView.podspec~ 6 | TKRoundedView.xcodeproj/xcuserdata/mapedd.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist 7 | TKRoundedView.xcodeproj/project.xcworkspace/xcshareddata/TKRoundedView.xccheckout 8 | TKRoundedView.xcodeproj/project.xcworkspace/xcuserdata/tomek.xcuserdatad/UserInterfaceState.xcuserstate 9 | TKRoundedView.xcodeproj/xcuserdata/tomek.xcuserdatad/xcschemes/TKRoundedView.xcscheme 10 | TKRoundedView.xcodeproj/xcuserdata/tomek.xcuserdatad/xcschemes/xcschememanagement.plist 11 | -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #TKRoundedView 2 | 3 | ##Features 4 | 5 | Simple rounded corners __without__ images 6 | 7 | ![Screenshot](https://dl.dropbox.com/u/450887/tkroundedview1.png) 8 | ![Screenshot](https://dl.dropbox.com/u/450887/tkroundedview2.png) 9 | 10 | ##Example usage 11 | 12 | NSArray *gradientColorsAndLocations = (@[ 13 | @{colorKey: [UIColor blackColor],locationKey: @(0.0f)}, 14 | @{colorKey: [UIColor lightGrayColor] ,locationKey: @(0.5f)}, 15 | @{colorKey: [UIColor whiteColor],locationKey: @(1.0f)} 16 | ]); 17 | 18 | TKRoundedView *view = [[TKRoundedView alloc] initWithFrame:frame]; 19 | view.roundedCorners = TKRoundedCornerTopLeft 20 | view.borderColor = [UIColor greenColor]; 21 | view.fillColor = [UIColor whiteColor]; 22 | view.gradientColorsAndLocations = gradientColorsAndLocations; 23 | view.gradientDirection = TKGradientDirectionDown; 24 | view.drawnBordersSides = TKDrawnBorderSidesLeft | TKDrawnBorderSidesTop; 25 | view.borderWidth = 5.0f; 26 | view.cornerRadius = 15.0f; 27 | 28 | ##Parameters 29 | 30 | - cornerRadius 31 | - borderWidth 32 | - borderColor 33 | - fillColor 34 | - rounded corners 35 | - drawn borders 36 | - gradient with any number of colors 37 | - gradient location 38 | 39 | 40 | ##Example project 41 | 42 | YES 43 | 44 | 45 | ##Contact 46 | 47 | - [@mapedd](https://twitter.com/mapedd) 48 | - [mapedd@mapedd.com](mapedd@gmail.com/ "Title") 49 | 50 | 51 | ##License 52 | 53 | Apache 54 | 55 | 56 | -------------------------------------------------------------------------------- /TKRoundedView.h: -------------------------------------------------------------------------------- 1 | // 2 | // TKRoundedView.h 3 | // TKRoundedView 4 | // 5 | // Created by Tomasz Kuźma on 1/6/13. 6 | // Copyright (c) 2013 Tomasz Kuźma. All rights reserved. 7 | // 8 | 9 | typedef NS_OPTIONS(NSUInteger, TKRoundedCorner) { 10 | TKRoundedCornerNone = 0, 11 | TKRoundedCornerTopRight = 1 << 0, 12 | TKRoundedCornerBottomRight = 1 << 1, 13 | TKRoundedCornerBottomLeft = 1 << 2, 14 | TKRoundedCornerTopLeft = 1 << 3, 15 | }; 16 | 17 | typedef NS_OPTIONS(NSUInteger, TKDrawnBorderSides) { 18 | TKDrawnBorderSidesNone = 0, 19 | TKDrawnBorderSidesRight = 1 << 0, 20 | TKDrawnBorderSidesLeft = 1 << 1, 21 | TKDrawnBorderSidesTop = 1 << 2, 22 | TKDrawnBorderSidesBottom = 1 << 3, 23 | }; 24 | 25 | typedef NS_ENUM(NSInteger, TKGradientDirection) { 26 | TKGradientDirectionHorizontal, 27 | TKGradientDirectionVertical, 28 | TKGradientDirectionUp, 29 | TKGradientDirectionDown, 30 | }; 31 | 32 | extern const TKRoundedCorner TKRoundedCornerAll; 33 | extern const TKDrawnBorderSides TKDrawnBorderSidesAll; 34 | 35 | UIImage * TKRoundedCornerImage(CGSize size, 36 | TKRoundedCorner corners, 37 | TKDrawnBorderSides drawnBorders, 38 | UIColor *fillColor, 39 | UIColor *borderColor, 40 | CGFloat borderWidth, 41 | CGFloat cornerRadius); 42 | 43 | @interface TKRoundedView : UIView 44 | 45 | /* Which borders should be drawn - default TKDrawnBordersSidesAll - only not rounded borders can *NOT* be drawn atm */ 46 | @property (nonatomic, assign) TKDrawnBorderSides drawnBordersSides; 47 | 48 | /* Which corners should be rounded - default TKRoundedCornerAll */ 49 | @property (nonatomic, assign) TKRoundedCorner roundedCorners; 50 | 51 | /* Fill color of the figure - default white */ 52 | @property (nonatomic, strong) UIColor *fillColor; 53 | 54 | /* Stroke color for the figure, default is light gray */ 55 | @property (nonatomic, strong) UIColor *borderColor; 56 | 57 | /* Border line width, default 1.0f */ 58 | @property (nonatomic, assign) CGFloat borderWidth; 59 | 60 | /* Corners radius , default 15.0f */ 61 | @property (nonatomic, assign) CGFloat cornerRadius; 62 | 63 | /* Direction of the gradient [options -, |, /, \] (if there will be a gradient drawn), default vertical */ 64 | @property (nonatomic, assign) TKGradientDirection gradientDirection; 65 | 66 | /* NSArray of NSDictionaries with NSNumber with color's locations and the UIColor object, default nil */ 67 | @property (nonatomic, strong) NSArray *gradientColorsAndLocations; 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /TKRoundedView.m: -------------------------------------------------------------------------------- 1 | // 2 | // TKRoundedView.m 3 | // TKRoundedView 4 | // 5 | // Created by Tomasz Kuźma on 1/6/13. 6 | // Copyright (c) 2013 Tomasz Kuźma. All rights reserved. 7 | // 8 | 9 | #import "TKRoundedView.h" 10 | #import 11 | 12 | const TKRoundedCorner TKRoundedCornerAll = TKRoundedCornerTopRight | TKRoundedCornerBottomRight | TKRoundedCornerBottomLeft | TKRoundedCornerTopLeft; 13 | 14 | const TKDrawnBorderSides TKDrawnBorderSidesAll = TKDrawnBorderSidesRight | TKDrawnBorderSidesLeft | TKDrawnBorderSidesTop | TKDrawnBorderSidesBottom; 15 | 16 | UIImage * TKRoundedCornerImage(CGSize size, 17 | TKRoundedCorner corners, 18 | TKDrawnBorderSides drawnBorders, 19 | UIColor *fillColor, 20 | UIColor *borderColor, 21 | CGFloat borderWidth, 22 | CGFloat cornerRadius){ 23 | 24 | TKRoundedView *view = [[TKRoundedView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, size.width, size.height)]; 25 | view.roundedCorners = corners; 26 | view.drawnBordersSides = drawnBorders; 27 | view.fillColor = fillColor; 28 | view.borderColor = borderColor; 29 | view.borderWidth = borderWidth; 30 | view.cornerRadius = cornerRadius; 31 | 32 | UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0); 33 | [view.layer renderInContext:UIGraphicsGetCurrentContext()]; 34 | 35 | UIImage * img = UIGraphicsGetImageFromCurrentImageContext(); 36 | 37 | UIGraphicsEndImageContext(); 38 | view = nil; 39 | 40 | return img; 41 | 42 | } 43 | 44 | @interface TKRoundedView (){ 45 | CGColorSpaceRef _colorSpace; 46 | CGFloat* _locationsTable; 47 | CFArrayRef _cfColors; 48 | CGGradientRef _gradient; 49 | NSArray *_observableKeys; 50 | } 51 | @end 52 | 53 | @implementation TKRoundedView 54 | 55 | #pragma mark - Initialization 56 | 57 | - (void)dealloc{ 58 | 59 | [self.observableKeys enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 60 | [self removeObserver:self forKeyPath:obj]; 61 | }]; 62 | 63 | if(_locationsTable != NULL) 64 | free(_locationsTable); 65 | 66 | if (_cfColors != NULL) { 67 | CFRelease(_cfColors); 68 | } 69 | 70 | if (_colorSpace != NULL) { 71 | CGColorSpaceRelease(_colorSpace); 72 | } 73 | 74 | if (_gradient != NULL) { 75 | CGGradientRelease(_gradient); 76 | } 77 | } 78 | 79 | - (id)initWithFrame:(CGRect)frame{ 80 | self = [super initWithFrame:frame]; 81 | if (!self)return nil; 82 | 83 | [self commonInit]; 84 | 85 | return self; 86 | } 87 | 88 | - (id)initWithCoder:(NSCoder *)aDecoder{ 89 | self = [super initWithCoder:aDecoder]; 90 | if (!self)return nil; 91 | 92 | [self commonInit]; 93 | 94 | return self; 95 | } 96 | 97 | - (void)commonInit{ 98 | 99 | self.opaque = NO; 100 | self.backgroundColor = [UIColor clearColor]; 101 | self.contentMode = UIViewContentModeRedraw; 102 | 103 | _gradientDirection = TKGradientDirectionVertical; 104 | _fillColor = [UIColor whiteColor]; 105 | _borderColor = [UIColor lightGrayColor]; 106 | _cornerRadius = 15.0f; 107 | _borderWidth = 1.0f; 108 | _roundedCorners = TKRoundedCornerAll; 109 | _drawnBordersSides = TKDrawnBorderSidesAll; 110 | 111 | [self.observableKeys enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 112 | [self addObserver:self forKeyPath:obj options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:nil]; 113 | }]; 114 | } 115 | 116 | #pragma mark - Drawing 117 | 118 | - (void)drawRect:(CGRect)rect{ 119 | CGContextRef ctx = UIGraphicsGetCurrentContext(); 120 | 121 | CGFloat halfLineWidth = _borderWidth / 2.0f; 122 | 123 | CGFloat topInsets = _drawnBordersSides & TKDrawnBorderSidesTop ? halfLineWidth : -halfLineWidth; 124 | CGFloat leftInsets = _drawnBordersSides & TKDrawnBorderSidesLeft ? halfLineWidth : -halfLineWidth; 125 | CGFloat rightInsets = _drawnBordersSides & TKDrawnBorderSidesRight ? halfLineWidth : -halfLineWidth; 126 | CGFloat bottomInsets = _drawnBordersSides & TKDrawnBorderSidesBottom ? halfLineWidth : -halfLineWidth; 127 | 128 | UIEdgeInsets insets = UIEdgeInsetsMake(topInsets, leftInsets, bottomInsets, rightInsets); 129 | 130 | CGRect properRect = UIEdgeInsetsInsetRect(rect, insets); 131 | 132 | /* Setup line width */ 133 | CGContextSetLineWidth(ctx, 0.0f); 134 | 135 | // Add and fill rect 136 | [self addPathToContext:ctx inRect:properRect respectDrawnBorder:NO]; 137 | 138 | // Close the path 139 | CGContextClosePath(ctx); 140 | 141 | if (_gradientColorsAndLocations.count) { 142 | CGContextSaveGState(ctx); 143 | CGContextClip(ctx); 144 | [self drawGradientToContext:ctx inRect:rect]; 145 | CGContextRestoreGState(ctx); 146 | } 147 | else{ 148 | // Fill and Stroke path 149 | CGContextSetFillColorWithColor(ctx, _fillColor.CGColor); 150 | CGContextDrawPath(ctx, kCGPathFill); 151 | } 152 | 153 | /* Setup colors and line width */ 154 | CGContextSetStrokeColorWithColor(ctx, _borderColor.CGColor); 155 | CGContextSetLineWidth(ctx, _borderWidth); 156 | 157 | // Add and stroke rect 158 | [self addPathToContext:ctx inRect:properRect respectDrawnBorder:YES]; 159 | 160 | // Fill and Stroke path 161 | CGContextDrawPath(ctx, kCGPathStroke); 162 | 163 | } 164 | 165 | - (void)addPathToContext:(CGContextRef)ctx inRect:(CGRect)rect respectDrawnBorder:(BOOL)respectDrawnBorders{ 166 | 167 | CGFloat minx = CGRectGetMinX(rect); 168 | CGFloat midx = CGRectGetMidX(rect); 169 | CGFloat maxx = CGRectGetMaxX(rect); 170 | 171 | CGFloat miny = CGRectGetMinY(rect); 172 | CGFloat midy = CGRectGetMidY(rect); 173 | CGFloat maxy = CGRectGetMaxY(rect); 174 | 175 | 176 | CGContextMoveToPoint(ctx, minx, midy); 177 | 178 | /* Top Left Corner */ 179 | if (_roundedCorners & TKRoundedCornerTopLeft && _drawnBordersSides & (TKDrawnBorderSidesTop | TKDrawnBorderSidesLeft)) { 180 | CGContextAddArcToPoint(ctx, minx, miny, midx, miny, _cornerRadius); 181 | CGContextAddLineToPoint(ctx, midx, miny); 182 | } 183 | else{ 184 | 185 | if (_drawnBordersSides & TKDrawnBorderSidesLeft || !respectDrawnBorders){ 186 | CGContextAddLineToPoint(ctx, minx, miny); 187 | } 188 | else{ 189 | CGContextDrawPath(ctx, kCGPathStroke); 190 | CGContextMoveToPoint(ctx, minx, miny); 191 | } 192 | 193 | if (_drawnBordersSides & TKDrawnBorderSidesTop || !respectDrawnBorders){ 194 | CGContextAddLineToPoint(ctx, midx, miny); 195 | } 196 | else{ 197 | CGContextDrawPath(ctx, kCGPathStroke); 198 | CGContextMoveToPoint(ctx, midx, miny); 199 | } 200 | } 201 | 202 | /* Top Right Corner */ 203 | if (_roundedCorners & TKRoundedCornerTopRight && _drawnBordersSides & (TKDrawnBorderSidesTop | TKDrawnBorderSidesRight)) { 204 | CGContextAddArcToPoint(ctx, maxx, miny, maxx, midy, _cornerRadius); 205 | CGContextAddLineToPoint(ctx, maxx, midy); 206 | } 207 | else{ 208 | 209 | if (_drawnBordersSides & TKDrawnBorderSidesTop || !respectDrawnBorders){ 210 | CGContextAddLineToPoint(ctx, maxx, miny); 211 | } 212 | else{ 213 | CGContextDrawPath(ctx, kCGPathStroke); 214 | CGContextMoveToPoint(ctx, maxx, miny); 215 | } 216 | 217 | if (_drawnBordersSides & TKDrawnBorderSidesRight || !respectDrawnBorders){ 218 | CGContextAddLineToPoint(ctx, maxx, midy); 219 | } 220 | else{ 221 | CGContextDrawPath(ctx, kCGPathStroke); 222 | CGContextMoveToPoint(ctx, maxx, midy); 223 | } 224 | } 225 | 226 | /* Bottom Right Corner */ 227 | if (_roundedCorners & TKRoundedCornerBottomRight && _drawnBordersSides & (TKDrawnBorderSidesBottom | TKDrawnBorderSidesRight)) { 228 | CGContextAddArcToPoint(ctx, maxx, maxy, midx, maxy, _cornerRadius); 229 | CGContextAddLineToPoint(ctx, midx, maxy); 230 | 231 | } 232 | else{ 233 | 234 | if (_drawnBordersSides & TKDrawnBorderSidesRight || !respectDrawnBorders){ 235 | CGContextAddLineToPoint(ctx, maxx, maxy); 236 | } 237 | else{ 238 | CGContextDrawPath(ctx, kCGPathStroke); 239 | CGContextMoveToPoint(ctx, maxx, maxy); 240 | } 241 | 242 | if (_drawnBordersSides & TKDrawnBorderSidesBottom || !respectDrawnBorders){ 243 | CGContextAddLineToPoint(ctx, midx, maxy); 244 | } 245 | else{ 246 | CGContextDrawPath(ctx, kCGPathStroke); 247 | CGContextMoveToPoint(ctx, midx, maxy); 248 | } 249 | } 250 | 251 | /* Bottom Left Corner */ 252 | if (_roundedCorners & TKRoundedCornerBottomLeft && _drawnBordersSides & (TKDrawnBorderSidesBottom | TKDrawnBorderSidesLeft)) { 253 | CGContextAddArcToPoint(ctx, minx, maxy, minx, midy, _cornerRadius); 254 | CGContextAddLineToPoint(ctx, minx, midy); 255 | } 256 | else{ 257 | 258 | if (_drawnBordersSides & TKDrawnBorderSidesBottom || !respectDrawnBorders){ 259 | CGContextAddLineToPoint(ctx, minx, maxy); 260 | } 261 | else{ 262 | CGContextDrawPath(ctx, kCGPathStroke); 263 | CGContextMoveToPoint(ctx, minx, maxy); 264 | } 265 | 266 | if (_drawnBordersSides & TKDrawnBorderSidesLeft || !respectDrawnBorders){ 267 | CGContextAddLineToPoint(ctx, minx, midy); 268 | } 269 | else{ 270 | CGContextMoveToPoint(ctx, minx, midy); 271 | CGContextDrawPath(ctx, kCGPathStroke); 272 | } 273 | 274 | } 275 | 276 | } 277 | 278 | - (void)drawGradientToContext:(CGContextRef)ctx inRect:(CGRect)rect{ 279 | 280 | if (_gradient == NULL) { 281 | _gradient = CGGradientCreateWithColors(_colorSpace,_cfColors, _locationsTable); 282 | } 283 | 284 | CGPoint startPoint = CGPointZero; 285 | CGPoint endPoint = CGPointZero; 286 | 287 | switch (_gradientDirection) { 288 | case TKGradientDirectionVertical: 289 | startPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect)); 290 | endPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect)); 291 | break; 292 | case TKGradientDirectionHorizontal: 293 | startPoint = CGPointMake(CGRectGetMinX(rect), CGRectGetMidY(rect)); 294 | endPoint = CGPointMake(CGRectGetMaxX(rect), CGRectGetMidY(rect)); 295 | break; 296 | case TKGradientDirectionDown: 297 | startPoint = CGPointMake(CGRectGetMinX(rect), CGRectGetMinY(rect)); 298 | endPoint = CGPointMake(CGRectGetMaxX(rect), CGRectGetMaxY(rect)); 299 | break; 300 | case TKGradientDirectionUp: 301 | startPoint = CGPointMake(CGRectGetMaxX(rect), CGRectGetMaxY(rect)); 302 | endPoint = CGPointMake(CGRectGetMinX(rect), CGRectGetMinY(rect)); 303 | break; 304 | 305 | default: 306 | break; 307 | } 308 | 309 | CGContextSaveGState(ctx); 310 | CGContextAddRect(ctx, rect); 311 | CGContextClip(ctx); 312 | CGContextDrawLinearGradient(ctx, _gradient, startPoint, endPoint, 0); 313 | CGContextRestoreGState(ctx); 314 | 315 | } 316 | 317 | //#pragma mark - Setters 318 | // 319 | //- (void)setDrawnBordersSides:(TKDrawnBorderSides)drawnBordersSides{ 320 | // _drawnBordersSides = drawnBordersSides; 321 | // [self setNeedsDisplay]; 322 | //} 323 | // 324 | //- (void)setRoundedCorners:(TKRoundedCorner)roundedCorners{ 325 | // _roundedCorners = roundedCorners; 326 | // [self setNeedsDisplay]; 327 | //} 328 | // 329 | //- (void)setBorderColor:(UIColor *)borderColor{ 330 | // if (_borderColor != borderColor) { 331 | // _borderColor = borderColor; 332 | // [self setNeedsDisplay]; 333 | // } 334 | //} 335 | // 336 | //- (void)setFillColor:(UIColor *)fillColor{ 337 | // if (_fillColor != fillColor) { 338 | // _fillColor = fillColor; 339 | // [self setNeedsDisplay]; 340 | // } 341 | //} 342 | // 343 | //- (void)setGradientColorsAndLocations:(NSArray *)gradientColorsAndLocations{ 344 | // if (_gradientColorsAndLocations != gradientColorsAndLocations) { 345 | // _gradientColorsAndLocations = gradientColorsAndLocations; 346 | // [self prepareGradient]; 347 | // [self setNeedsDisplay]; 348 | // } 349 | //} 350 | // 351 | //- (void)setGradientDirection:(TKGradientDirection)gradientDirection{ 352 | // if (_gradientDirection != gradientDirection) { 353 | // _gradientDirection = gradientDirection; 354 | // [self setNeedsDisplay]; 355 | // } 356 | //} 357 | // 358 | //- (void)setBorderWidth:(CGFloat)borderWidth{ 359 | // _borderWidth = borderWidth; 360 | // [self setNeedsDisplay]; 361 | //} 362 | // 363 | //- (void)setCornerRadius:(CGFloat)cornerRadius{ 364 | // _cornerRadius = cornerRadius; 365 | // [self setNeedsDisplay]; 366 | //} 367 | 368 | 369 | #pragma mark - Key-Value Observing 370 | 371 | + (BOOL)automaticallyNotifiesObserversForKey:(NSString *)key{ 372 | return YES; 373 | } 374 | 375 | 376 | - (void)observeValueForKeyPath:(NSString *)keyPath 377 | ofObject:(id)object change:(NSDictionary *)change context:(void *)context 378 | { 379 | if ([keyPath isEqualToString:@"gradientColorsAndLocations"]) 380 | { 381 | [self prepareGradient]; 382 | [self setNeedsDisplay]; 383 | return ; 384 | } 385 | 386 | [self.observableKeys enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop){ 387 | if ([keyPath isEqualToString:obj]) 388 | { 389 | [self setNeedsDisplay]; 390 | return; 391 | } 392 | }]; 393 | } 394 | 395 | 396 | - (void)didChange:(NSKeyValueChange)changeKind valuesAtIndexes:(NSIndexSet *)indexes forKey:(NSString *)key{ 397 | 398 | if ([key isEqualToString:@"gradientColorsAndLocations"]) 399 | { 400 | [self prepareGradient]; 401 | [self setNeedsDisplay]; 402 | } 403 | } 404 | 405 | - (NSArray *)observableKeys{ 406 | if (!_observableKeys) { 407 | _observableKeys = (@[ 408 | @"drawnBordersSides", 409 | @"roundedCorners", 410 | @"fillColor", 411 | @"borderColor", 412 | @"borderWidth", 413 | @"cornerRadius", 414 | @"gradientDirection", 415 | @"gradientColorsAndLocations" 416 | ]); 417 | } 418 | return _observableKeys; 419 | } 420 | 421 | #pragma mark - Private 422 | 423 | - (void)prepareGradient{ 424 | NSMutableArray *colors = [NSMutableArray arrayWithCapacity:_gradientColorsAndLocations.count]; 425 | NSMutableArray *locations = [NSMutableArray arrayWithCapacity:_gradientColorsAndLocations.count]; 426 | 427 | for (NSDictionary *dictionary in self.gradientColorsAndLocations) { 428 | if ([dictionary isKindOfClass:[NSDictionary class]]) { 429 | for (NSString *key in dictionary) { 430 | id object = dictionary[key]; 431 | if ([object isKindOfClass:[NSNumber class]]) { 432 | [locations addObject:object]; 433 | } 434 | else if ([object isKindOfClass:[UIColor class]]){ 435 | [colors addObject:object]; 436 | } 437 | } 438 | } 439 | } 440 | 441 | if (colors.count == locations.count) { 442 | 443 | if (_colorSpace == NULL) { 444 | _colorSpace = CGColorSpaceCreateDeviceRGB(); 445 | } 446 | 447 | NSInteger count = locations.count; 448 | 449 | 450 | if (_locationsTable != NULL) { 451 | free(_locationsTable); 452 | } 453 | 454 | _locationsTable = malloc((size_t) sizeof(CGFloat) * count); 455 | 456 | CFMutableArrayRef cfColorsMutable = CFArrayCreateMutable(kCFAllocatorDefault, count, &kCFTypeArrayCallBacks); 457 | 458 | for(int i = 0; i < count; i++){ 459 | NSNumber *locationNumber = locations[i]; 460 | _locationsTable[i] = [locationNumber floatValue]; 461 | CGColorRef color = [colors[i] CGColor]; 462 | CFArrayAppendValue(cfColorsMutable, color); 463 | } 464 | 465 | if (_cfColors != NULL) { 466 | CFRelease(_cfColors); 467 | } 468 | _cfColors = CFArrayCreateCopy(kCFAllocatorDefault, cfColorsMutable); 469 | 470 | CFRelease(cfColorsMutable); 471 | 472 | if (_gradient != NULL) { 473 | CGGradientRelease(_gradient); 474 | _gradient = NULL; 475 | } 476 | } 477 | } 478 | 479 | @end 480 | -------------------------------------------------------------------------------- /TKRoundedView.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "TKRoundedView" 3 | s.version = "0.5" 4 | s.summary = "Rounded corners without images and much more." 5 | s.homepage = "http://github.com/mapedd/TKRoundedView" 6 | s.license = 'Apache' 7 | s.author = { "Tomek Kuzma" => "mapedd@mapedd.com" } 8 | s.source = { :git => "https://github.com/mapedd/TKRoundedView.git", :tag => "0.5" } 9 | s.platform = :ios 10 | s.source_files = 'TKRoundedView.{h,m}' 11 | s.requires_arc = true 12 | end 13 | -------------------------------------------------------------------------------- /TKRoundedView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 0474D9951699EE5400110CD5 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0474D9941699EE5400110CD5 /* UIKit.framework */; }; 11 | 0474D9971699EE5400110CD5 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0474D9961699EE5400110CD5 /* Foundation.framework */; }; 12 | 0474D9991699EE5400110CD5 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0474D9981699EE5400110CD5 /* CoreGraphics.framework */; }; 13 | 0474D99F1699EE5400110CD5 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0474D99D1699EE5400110CD5 /* InfoPlist.strings */; }; 14 | 0474D9A11699EE5400110CD5 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 0474D9A01699EE5400110CD5 /* main.m */; }; 15 | 0474D9A51699EE5400110CD5 /* TKAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 0474D9A41699EE5400110CD5 /* TKAppDelegate.m */; }; 16 | 0474D9A71699EE5400110CD5 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 0474D9A61699EE5400110CD5 /* Default.png */; }; 17 | 0474D9A91699EE5400110CD5 /* Default@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 0474D9A81699EE5400110CD5 /* Default@2x.png */; }; 18 | 0474D9AB1699EE5400110CD5 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 0474D9AA1699EE5400110CD5 /* Default-568h@2x.png */; }; 19 | 0474D9AE1699EE5400110CD5 /* TKViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0474D9AD1699EE5400110CD5 /* TKViewController.m */; }; 20 | 0474D9CB1699F0F700110CD5 /* TKRoundedView.m in Sources */ = {isa = PBXBuildFile; fileRef = 0474D9CA1699F0F700110CD5 /* TKRoundedView.m */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXFileReference section */ 24 | 0474D9901699EE5400110CD5 /* TKRoundedView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TKRoundedView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 25 | 0474D9941699EE5400110CD5 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 26 | 0474D9961699EE5400110CD5 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 27 | 0474D9981699EE5400110CD5 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 28 | 0474D99C1699EE5400110CD5 /* TKRoundedView-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "TKRoundedView-Info.plist"; sourceTree = ""; }; 29 | 0474D99E1699EE5400110CD5 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 30 | 0474D9A01699EE5400110CD5 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 31 | 0474D9A21699EE5400110CD5 /* TKRoundedView-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "TKRoundedView-Prefix.pch"; sourceTree = ""; }; 32 | 0474D9A31699EE5400110CD5 /* TKAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TKAppDelegate.h; sourceTree = ""; }; 33 | 0474D9A41699EE5400110CD5 /* TKAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TKAppDelegate.m; sourceTree = ""; }; 34 | 0474D9A61699EE5400110CD5 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = ""; }; 35 | 0474D9A81699EE5400110CD5 /* Default@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default@2x.png"; sourceTree = ""; }; 36 | 0474D9AA1699EE5400110CD5 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; 37 | 0474D9AC1699EE5400110CD5 /* TKViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TKViewController.h; sourceTree = ""; }; 38 | 0474D9AD1699EE5400110CD5 /* TKViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TKViewController.m; sourceTree = ""; }; 39 | 0474D9C91699F0F700110CD5 /* TKRoundedView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TKRoundedView.h; sourceTree = SOURCE_ROOT; }; 40 | 0474D9CA1699F0F700110CD5 /* TKRoundedView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TKRoundedView.m; sourceTree = SOURCE_ROOT; }; 41 | /* End PBXFileReference section */ 42 | 43 | /* Begin PBXFrameworksBuildPhase section */ 44 | 0474D98D1699EE5400110CD5 /* Frameworks */ = { 45 | isa = PBXFrameworksBuildPhase; 46 | buildActionMask = 2147483647; 47 | files = ( 48 | 0474D9951699EE5400110CD5 /* UIKit.framework in Frameworks */, 49 | 0474D9971699EE5400110CD5 /* Foundation.framework in Frameworks */, 50 | 0474D9991699EE5400110CD5 /* CoreGraphics.framework in Frameworks */, 51 | ); 52 | runOnlyForDeploymentPostprocessing = 0; 53 | }; 54 | /* End PBXFrameworksBuildPhase section */ 55 | 56 | /* Begin PBXGroup section */ 57 | 0474D9851699EE5400110CD5 = { 58 | isa = PBXGroup; 59 | children = ( 60 | 0474D99A1699EE5400110CD5 /* TKRoundedView */, 61 | 0474D9931699EE5400110CD5 /* Frameworks */, 62 | 0474D9911699EE5400110CD5 /* Products */, 63 | ); 64 | sourceTree = ""; 65 | }; 66 | 0474D9911699EE5400110CD5 /* Products */ = { 67 | isa = PBXGroup; 68 | children = ( 69 | 0474D9901699EE5400110CD5 /* TKRoundedView.app */, 70 | ); 71 | name = Products; 72 | sourceTree = ""; 73 | }; 74 | 0474D9931699EE5400110CD5 /* Frameworks */ = { 75 | isa = PBXGroup; 76 | children = ( 77 | 0474D9941699EE5400110CD5 /* UIKit.framework */, 78 | 0474D9961699EE5400110CD5 /* Foundation.framework */, 79 | 0474D9981699EE5400110CD5 /* CoreGraphics.framework */, 80 | ); 81 | name = Frameworks; 82 | sourceTree = ""; 83 | }; 84 | 0474D99A1699EE5400110CD5 /* TKRoundedView */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | 0474D9C91699F0F700110CD5 /* TKRoundedView.h */, 88 | 0474D9CA1699F0F700110CD5 /* TKRoundedView.m */, 89 | 0474D9A31699EE5400110CD5 /* TKAppDelegate.h */, 90 | 0474D9A41699EE5400110CD5 /* TKAppDelegate.m */, 91 | 0474D9AC1699EE5400110CD5 /* TKViewController.h */, 92 | 0474D9AD1699EE5400110CD5 /* TKViewController.m */, 93 | 0474D99B1699EE5400110CD5 /* Supporting Files */, 94 | ); 95 | path = TKRoundedView; 96 | sourceTree = ""; 97 | }; 98 | 0474D99B1699EE5400110CD5 /* Supporting Files */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | 0474D99C1699EE5400110CD5 /* TKRoundedView-Info.plist */, 102 | 0474D99D1699EE5400110CD5 /* InfoPlist.strings */, 103 | 0474D9A01699EE5400110CD5 /* main.m */, 104 | 0474D9A21699EE5400110CD5 /* TKRoundedView-Prefix.pch */, 105 | 0474D9A61699EE5400110CD5 /* Default.png */, 106 | 0474D9A81699EE5400110CD5 /* Default@2x.png */, 107 | 0474D9AA1699EE5400110CD5 /* Default-568h@2x.png */, 108 | ); 109 | name = "Supporting Files"; 110 | sourceTree = ""; 111 | }; 112 | /* End PBXGroup section */ 113 | 114 | /* Begin PBXNativeTarget section */ 115 | 0474D98F1699EE5400110CD5 /* TKRoundedView */ = { 116 | isa = PBXNativeTarget; 117 | buildConfigurationList = 0474D9B71699EE5400110CD5 /* Build configuration list for PBXNativeTarget "TKRoundedView" */; 118 | buildPhases = ( 119 | 0474D98C1699EE5400110CD5 /* Sources */, 120 | 0474D98D1699EE5400110CD5 /* Frameworks */, 121 | 0474D98E1699EE5400110CD5 /* Resources */, 122 | ); 123 | buildRules = ( 124 | ); 125 | dependencies = ( 126 | ); 127 | name = TKRoundedView; 128 | productName = TKRoundedView; 129 | productReference = 0474D9901699EE5400110CD5 /* TKRoundedView.app */; 130 | productType = "com.apple.product-type.application"; 131 | }; 132 | /* End PBXNativeTarget section */ 133 | 134 | /* Begin PBXProject section */ 135 | 0474D9871699EE5400110CD5 /* Project object */ = { 136 | isa = PBXProject; 137 | attributes = { 138 | CLASSPREFIX = TK; 139 | LastUpgradeCheck = 0450; 140 | ORGANIZATIONNAME = mapedd; 141 | }; 142 | buildConfigurationList = 0474D98A1699EE5400110CD5 /* Build configuration list for PBXProject "TKRoundedView" */; 143 | compatibilityVersion = "Xcode 3.2"; 144 | developmentRegion = English; 145 | hasScannedForEncodings = 0; 146 | knownRegions = ( 147 | en, 148 | ); 149 | mainGroup = 0474D9851699EE5400110CD5; 150 | productRefGroup = 0474D9911699EE5400110CD5 /* Products */; 151 | projectDirPath = ""; 152 | projectRoot = ""; 153 | targets = ( 154 | 0474D98F1699EE5400110CD5 /* TKRoundedView */, 155 | ); 156 | }; 157 | /* End PBXProject section */ 158 | 159 | /* Begin PBXResourcesBuildPhase section */ 160 | 0474D98E1699EE5400110CD5 /* Resources */ = { 161 | isa = PBXResourcesBuildPhase; 162 | buildActionMask = 2147483647; 163 | files = ( 164 | 0474D99F1699EE5400110CD5 /* InfoPlist.strings in Resources */, 165 | 0474D9A71699EE5400110CD5 /* Default.png in Resources */, 166 | 0474D9A91699EE5400110CD5 /* Default@2x.png in Resources */, 167 | 0474D9AB1699EE5400110CD5 /* Default-568h@2x.png in Resources */, 168 | ); 169 | runOnlyForDeploymentPostprocessing = 0; 170 | }; 171 | /* End PBXResourcesBuildPhase section */ 172 | 173 | /* Begin PBXSourcesBuildPhase section */ 174 | 0474D98C1699EE5400110CD5 /* Sources */ = { 175 | isa = PBXSourcesBuildPhase; 176 | buildActionMask = 2147483647; 177 | files = ( 178 | 0474D9A11699EE5400110CD5 /* main.m in Sources */, 179 | 0474D9A51699EE5400110CD5 /* TKAppDelegate.m in Sources */, 180 | 0474D9AE1699EE5400110CD5 /* TKViewController.m in Sources */, 181 | 0474D9CB1699F0F700110CD5 /* TKRoundedView.m in Sources */, 182 | ); 183 | runOnlyForDeploymentPostprocessing = 0; 184 | }; 185 | /* End PBXSourcesBuildPhase section */ 186 | 187 | /* Begin PBXVariantGroup section */ 188 | 0474D99D1699EE5400110CD5 /* InfoPlist.strings */ = { 189 | isa = PBXVariantGroup; 190 | children = ( 191 | 0474D99E1699EE5400110CD5 /* en */, 192 | ); 193 | name = InfoPlist.strings; 194 | sourceTree = ""; 195 | }; 196 | /* End PBXVariantGroup section */ 197 | 198 | /* Begin XCBuildConfiguration section */ 199 | 0474D9B51699EE5400110CD5 /* Debug */ = { 200 | isa = XCBuildConfiguration; 201 | buildSettings = { 202 | ALWAYS_SEARCH_USER_PATHS = NO; 203 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 204 | CLANG_CXX_LIBRARY = "libc++"; 205 | CLANG_ENABLE_OBJC_ARC = YES; 206 | CLANG_WARN_EMPTY_BODY = YES; 207 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 208 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 209 | COPY_PHASE_STRIP = NO; 210 | GCC_C_LANGUAGE_STANDARD = gnu99; 211 | GCC_DYNAMIC_NO_PIC = NO; 212 | GCC_OPTIMIZATION_LEVEL = 0; 213 | GCC_PREPROCESSOR_DEFINITIONS = ( 214 | "DEBUG=1", 215 | "$(inherited)", 216 | ); 217 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 218 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 219 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 220 | GCC_WARN_UNUSED_VARIABLE = YES; 221 | IPHONEOS_DEPLOYMENT_TARGET = 6.0; 222 | ONLY_ACTIVE_ARCH = YES; 223 | SDKROOT = iphoneos; 224 | TARGETED_DEVICE_FAMILY = "1,2"; 225 | }; 226 | name = Debug; 227 | }; 228 | 0474D9B61699EE5400110CD5 /* Release */ = { 229 | isa = XCBuildConfiguration; 230 | buildSettings = { 231 | ALWAYS_SEARCH_USER_PATHS = NO; 232 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 233 | CLANG_CXX_LIBRARY = "libc++"; 234 | CLANG_ENABLE_OBJC_ARC = YES; 235 | CLANG_WARN_EMPTY_BODY = YES; 236 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 237 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 238 | COPY_PHASE_STRIP = YES; 239 | GCC_C_LANGUAGE_STANDARD = gnu99; 240 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 241 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 242 | GCC_WARN_UNUSED_VARIABLE = YES; 243 | IPHONEOS_DEPLOYMENT_TARGET = 6.0; 244 | OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; 245 | SDKROOT = iphoneos; 246 | TARGETED_DEVICE_FAMILY = "1,2"; 247 | VALIDATE_PRODUCT = YES; 248 | }; 249 | name = Release; 250 | }; 251 | 0474D9B81699EE5400110CD5 /* Debug */ = { 252 | isa = XCBuildConfiguration; 253 | buildSettings = { 254 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 255 | GCC_PREFIX_HEADER = "TKRoundedView/TKRoundedView-Prefix.pch"; 256 | INFOPLIST_FILE = "TKRoundedView/TKRoundedView-Info.plist"; 257 | PRODUCT_NAME = "$(TARGET_NAME)"; 258 | WRAPPER_EXTENSION = app; 259 | }; 260 | name = Debug; 261 | }; 262 | 0474D9B91699EE5400110CD5 /* Release */ = { 263 | isa = XCBuildConfiguration; 264 | buildSettings = { 265 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 266 | GCC_PREFIX_HEADER = "TKRoundedView/TKRoundedView-Prefix.pch"; 267 | INFOPLIST_FILE = "TKRoundedView/TKRoundedView-Info.plist"; 268 | PRODUCT_NAME = "$(TARGET_NAME)"; 269 | WRAPPER_EXTENSION = app; 270 | }; 271 | name = Release; 272 | }; 273 | /* End XCBuildConfiguration section */ 274 | 275 | /* Begin XCConfigurationList section */ 276 | 0474D98A1699EE5400110CD5 /* Build configuration list for PBXProject "TKRoundedView" */ = { 277 | isa = XCConfigurationList; 278 | buildConfigurations = ( 279 | 0474D9B51699EE5400110CD5 /* Debug */, 280 | 0474D9B61699EE5400110CD5 /* Release */, 281 | ); 282 | defaultConfigurationIsVisible = 0; 283 | defaultConfigurationName = Release; 284 | }; 285 | 0474D9B71699EE5400110CD5 /* Build configuration list for PBXNativeTarget "TKRoundedView" */ = { 286 | isa = XCConfigurationList; 287 | buildConfigurations = ( 288 | 0474D9B81699EE5400110CD5 /* Debug */, 289 | 0474D9B91699EE5400110CD5 /* Release */, 290 | ); 291 | defaultConfigurationIsVisible = 0; 292 | defaultConfigurationName = Release; 293 | }; 294 | /* End XCConfigurationList section */ 295 | }; 296 | rootObject = 0474D9871699EE5400110CD5 /* Project object */; 297 | } 298 | -------------------------------------------------------------------------------- /TKRoundedView/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapedd/TKRoundedView/f031c6c06f7d6f924d369a783891283ce03ea399/TKRoundedView/Default-568h@2x.png -------------------------------------------------------------------------------- /TKRoundedView/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapedd/TKRoundedView/f031c6c06f7d6f924d369a783891283ce03ea399/TKRoundedView/Default.png -------------------------------------------------------------------------------- /TKRoundedView/Default@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapedd/TKRoundedView/f031c6c06f7d6f924d369a783891283ce03ea399/TKRoundedView/Default@2x.png -------------------------------------------------------------------------------- /TKRoundedView/TKAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // TKAppDelegate.h 3 | // TKRoundedView 4 | // 5 | // Created by Tomasz Kuźma on 1/6/13. 6 | // Copyright (c) 2013 mapedd. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class TKViewController; 12 | 13 | @interface TKAppDelegate : UIResponder 14 | 15 | @property (strong, nonatomic) UIWindow *window; 16 | 17 | @property (strong, nonatomic) TKViewController *viewController; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /TKRoundedView/TKAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // TKAppDelegate.m 3 | // TKRoundedView 4 | // 5 | // Created by Tomasz Kuźma on 1/6/13. 6 | // Copyright (c) 2013 mapedd. All rights reserved. 7 | // 8 | 9 | #import "TKAppDelegate.h" 10 | 11 | #import "TKViewController.h" 12 | 13 | @implementation TKAppDelegate 14 | 15 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ 16 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 17 | self.viewController = [[TKViewController alloc] init]; 18 | self.window.rootViewController = self.viewController; 19 | [self.window makeKeyAndVisible]; 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application{ 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application{ 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application{ 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application{ 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application{ 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /TKRoundedView/TKRoundedView-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | mapedd.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /TKRoundedView/TKRoundedView-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'TKRoundedView' target in the 'TKRoundedView' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_4_0 8 | #warning "This project uses features only available in iOS SDK 4.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /TKRoundedView/TKViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // TKViewController.h 3 | // TKRoundedView 4 | // 5 | // Created by Tomasz Kuźma on 1/6/13. 6 | // Copyright (c) 2013 mapedd. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface TKViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /TKRoundedView/TKViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // TKViewController.m 3 | // TKRoundedView 4 | // 5 | // Created by Tomasz Kuźma on 1/6/13. 6 | // Copyright (c) 2013 mapedd. All rights reserved. 7 | // 8 | 9 | #import "TKViewController.h" 10 | #import "TKRoundedView.h" 11 | 12 | @interface TKViewController () 13 | @property (nonatomic, strong) UISwitch *aSwitch; 14 | @property (nonatomic, strong) UILabel *label; 15 | @end 16 | 17 | @implementation TKViewController 18 | 19 | - (id)init{ 20 | self = [super initWithNibName:nil bundle:nil]; 21 | if(!self)return nil; 22 | return self; 23 | } 24 | 25 | - (void)viewDidLoad{ 26 | [super viewDidLoad]; 27 | 28 | self.view.backgroundColor = [UIColor whiteColor]; 29 | 30 | self.aSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 90 , self.view.frame.size.height - 34, 88, 44)]; 31 | [self.view addSubview:_aSwitch]; 32 | [_aSwitch addTarget:self action:@selector(switchSwitched:) forControlEvents:UIControlEventValueChanged]; 33 | _aSwitch.on = NO; 34 | 35 | [self switchSwitched:_aSwitch]; 36 | 37 | self.label = [[UILabel alloc] initWithFrame:CGRectMake(10, self.view.frame.size.height - 34, self.view.frame.size.width - 105 , _aSwitch.frame.size.height)]; 38 | _label.text = @"borders on/off"; 39 | _label.textAlignment = NSTextAlignmentCenter; 40 | _label.textColor = [UIColor blackColor]; 41 | [self.view addSubview:_label]; 42 | } 43 | 44 | - (void)switchSwitched:(UISwitch *)theSwitch{ 45 | [self showCornersOrBorders:theSwitch.on]; 46 | } 47 | 48 | - (void)didReceiveMemoryWarning{ 49 | [super didReceiveMemoryWarning]; 50 | } 51 | 52 | - (void)showCornersOrBorders:(BOOL)corners{ 53 | 54 | for (UIView *subview in self.view.subviews) { 55 | if (subview != _aSwitch && subview != _label) { 56 | [subview removeFromSuperview]; 57 | } 58 | 59 | } 60 | 61 | NSString *colorKey = @"color"; 62 | NSString *locationKey = @"location"; 63 | 64 | 65 | TKGradientDirection gradientDirection = TKGradientDirectionDown; 66 | 67 | CGFloat offset = 10.0f; 68 | 69 | CGFloat side = (self.view.frame.size.width - 4 * offset)/ 3.0f ; 70 | 71 | CGRect frame = CGRectMake(offset, offset, side, side); 72 | 73 | if (corners) { 74 | 75 | TKRoundedCorner cornerOptions[13] = { 76 | TKRoundedCornerNone, 77 | TKRoundedCornerAll, 78 | TKRoundedCornerTopLeft, 79 | TKRoundedCornerTopRight, 80 | TKRoundedCornerBottomRight, 81 | TKRoundedCornerBottomLeft, 82 | TKRoundedCornerTopLeft | TKRoundedCornerTopRight, 83 | TKRoundedCornerBottomLeft | TKRoundedCornerBottomRight, 84 | TKRoundedCornerTopLeft | TKRoundedCornerBottomRight, 85 | TKRoundedCornerBottomLeft | TKRoundedCornerTopRight, 86 | TKRoundedCornerTopLeft | TKRoundedCornerTopRight, 87 | TKRoundedCornerTopLeft | TKRoundedCornerTopRight | TKRoundedCornerBottomRight, 88 | TKRoundedCornerTopLeft | TKRoundedCornerTopRight | TKRoundedCornerBottomLeft, 89 | }; 90 | 91 | NSArray *gradientColorsAndLocations = (@[ 92 | @{colorKey: [UIColor blackColor],locationKey: @(0.0f)}, 93 | @{colorKey: [UIColor lightGrayColor] ,locationKey: @(0.5f)}, 94 | @{colorKey: [UIColor whiteColor],locationKey: @(1.0f)} 95 | ]); 96 | 97 | for (int i = 0; i < 13; i++) { 98 | 99 | TKRoundedView *view1 = [[TKRoundedView alloc] initWithFrame:CGRectInset(frame, 10, 10)]; 100 | view1.roundedCorners = cornerOptions[i]; 101 | view1.borderColor = [UIColor colorWithRed:0.123 green:0.435 blue:0.52 alpha:1.0]; 102 | view1.fillColor = [UIColor colorWithWhite:0.6 alpha:0.1]; 103 | view1.borderWidth = 5.0f; 104 | view1.gradientColorsAndLocations = gradientColorsAndLocations; 105 | view1.gradientDirection = gradientDirection; 106 | view1.cornerRadius = side/4; 107 | [self.view addSubview:view1]; 108 | 109 | frame.origin.y += side + offset; 110 | 111 | if (self.view.frame.size.height < CGRectGetMaxY(frame)) { 112 | frame.origin.y = offset; 113 | frame.origin.x += offset + side; 114 | } 115 | 116 | } 117 | } 118 | else{ 119 | 120 | NSArray *gradientColorsAndLocations = (@[ 121 | @{colorKey: [UIColor colorWithRed:0.0f green:137.0f/255.0f blue:248.0f/255.0f alpha:1.0f],locationKey: @(0.0f)}, 122 | @{colorKey: [UIColor colorWithRed:0.0f green:89.0f/255.0f blue:234.0f/255.0f alpha:1.0f],locationKey: @(1.0f)} 123 | ]); 124 | 125 | 126 | for (int i = 0; i < 10; i++) { 127 | 128 | TKRoundedView *view1 = [[TKRoundedView alloc] initWithFrame:frame]; 129 | 130 | 131 | if (i == 0) { 132 | view1.roundedCorners = TKRoundedCornerTopLeft | TKRoundedCornerTopRight; 133 | view1.drawnBordersSides = TKDrawnBorderSidesLeft | TKDrawnBorderSidesTop | TKDrawnBorderSidesRight; 134 | } 135 | else if(i == 1){ 136 | view1.roundedCorners = TKRoundedCornerBottomLeft | TKRoundedCornerBottomRight; 137 | view1.drawnBordersSides = TKDrawnBorderSidesLeft | TKDrawnBorderSidesBottom | TKDrawnBorderSidesRight; 138 | } 139 | else if(i == 2){ 140 | view1.roundedCorners = TKRoundedCornerNone; 141 | view1.drawnBordersSides = TKDrawnBorderSidesLeft | TKDrawnBorderSidesRight; 142 | } 143 | else if(i == 3){ 144 | view1.roundedCorners = TKRoundedCornerAll; 145 | view1.drawnBordersSides = TKDrawnBorderSidesAll; 146 | } 147 | else if(i == 4){ 148 | view1.roundedCorners = TKRoundedCornerBottomLeft | TKRoundedCornerTopLeft; 149 | view1.drawnBordersSides = TKDrawnBorderSidesLeft | TKDrawnBorderSidesBottom | TKDrawnBorderSidesTop; 150 | } 151 | else if(i == 5){ 152 | view1.roundedCorners = TKRoundedCornerBottomRight | TKRoundedCornerTopRight; 153 | view1.drawnBordersSides = TKDrawnBorderSidesRight | TKDrawnBorderSidesBottom | TKDrawnBorderSidesTop; 154 | } 155 | else if(i == 6){ 156 | view1.roundedCorners = TKRoundedCornerNone; 157 | view1.drawnBordersSides = TKDrawnBorderSidesTop| TKDrawnBorderSidesBottom; 158 | } 159 | else if(i == 7){ 160 | view1.roundedCorners = TKRoundedCornerNone; 161 | view1.drawnBordersSides = TKDrawnBorderSidesAll; 162 | } 163 | else if(i == 8){ 164 | view1.roundedCorners = TKRoundedCornerBottomRight; 165 | view1.drawnBordersSides = TKDrawnBorderSidesRight | TKDrawnBorderSidesBottom; 166 | } 167 | else if(i == 9){ 168 | view1.roundedCorners = TKRoundedCornerTopLeft; 169 | view1.drawnBordersSides = TKDrawnBorderSidesLeft | TKDrawnBorderSidesTop; 170 | } 171 | 172 | view1.borderColor = [UIColor colorWithRed:1.000 green:0.899 blue:0.520 alpha:1.000]; 173 | view1.fillColor = [UIColor redColor]; 174 | view1.gradientColorsAndLocations = gradientColorsAndLocations; 175 | view1.borderWidth = 5.0f; 176 | view1.cornerRadius = 30.0f; 177 | [self.view addSubview:view1]; 178 | 179 | frame.origin.y += offset + side; 180 | 181 | if (self.view.frame.size.height < CGRectGetMaxY(frame)) { 182 | frame.origin.y = offset; 183 | frame.origin.x += offset + side; 184 | } 185 | 186 | } 187 | 188 | } 189 | 190 | [self.view bringSubviewToFront:_aSwitch]; 191 | 192 | } 193 | 194 | @end 195 | -------------------------------------------------------------------------------- /TKRoundedView/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /TKRoundedView/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // TKRoundedView 4 | // 5 | // Created by Tomasz Kuźma on 1/6/13. 6 | // Copyright (c) 2013 mapedd. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "TKAppDelegate.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([TKAppDelegate class])); 17 | } 18 | } 19 | --------------------------------------------------------------------------------