├── CHANGELOG ├── TODO ├── UIColor+i7HexColor.h ├── COPYRIGHT ├── README ├── LICENSE └── UIColor+i7HexColor.m /CHANGELOG: -------------------------------------------------------------------------------- 1 | 08/13/2010 - Jonas Schnelli 2 | + fixed huge problem when hex color string starts with "0". 3 | 4 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | + (check) check if methode swizzling is tolerated in the app store (review process / IMP manipluation / private call) 2 | -------------------------------------------------------------------------------- /UIColor+i7HexColor.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+i7HexColor.h 3 | // 4 | // 5 | // Created by Jonas Schnelli on 01.07.10. 6 | // Copyright 2010 include7 AG. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface UIColor (i7HexColor) 13 | 14 | + (UIColor *)colorWithHexString:(NSString *)hexString; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /COPYRIGHT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 include7 AG – Jonas Schnelli 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This UIColor Categorie (Extend) will allow you to create UIColor instances with a "Color-Hex-NSString". 2 | Example: 3 | --- 4 | label.textColor = [UIColor colorWithHexString:@"ff0000"]; // red color 5 | //or 6 | label.textColor = [UIColor colorWithHexString:@"f00"]; // red color 7 | //or 8 | label.textColor = [UIColor colorWithHexString:@"ff000055"]; // red color with some alpha 9 | --- 10 | 11 | Version 12 | ======= 13 | 0.11 14 | 15 | License 16 | ======= 17 | BSD 18 | 19 | Changelog 20 | ========== 21 | 07/01/2010 – Version 0.1 - package started 22 | 08/13/2010 – Version 0.11 - + fixed huge problem when hex color string starts with "0". 23 | 24 | Author 25 | ====== 26 | Jonas Schnelli / include7 AG - www.include7.ch 27 | 28 | 29 | _ __ __ _____ 30 | (_)___ _____/ /_ ______/ /_/__ / 31 | / / __ \/ ___/ / / / / __ / _ \/ / 32 | / / / / / /__/ / /_/ / /_/ / __/ / 33 | /_/_/ /_/\___/_/\__,_/\__,_/\___/_/........ 34 | 35 | 36 | 37 | URL 38 | === 39 | http://github.com/jonasschnelli/UIColor-i7HexColor 40 | 41 | Info 42 | ==== 43 | Have fun while using and extending this package. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | copyright (c) 2010 include7 AG – Jonas Schnelli 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1) Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | 2) Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | 3) All advertising materials mentioning features or use of this software 16 | must display the following acknowledgement: “This product includes software 17 | developed by the include7 AG, Switzerland and its contributors.” 18 | 19 | 4) Neither the name of the include7 AG, Switzerland nor the names of 20 | its contributors may be used to endorse or promote products derived from 21 | this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INCLUDE7 AG OR CONTRIBUTORS BE 27 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | POSSIBILITY OF SUCH DAMAGE. 34 | 35 | -------------------------------------------------------------------------------- /UIColor+i7HexColor.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+i7HexColor.m 3 | // 4 | // 5 | // Created by Jonas Schnelli on 01.07.10. 6 | // Copyright 2010 include7 AG. All rights reserved. 7 | // 8 | 9 | #import "UIColor+i7HexColor.h" 10 | 11 | 12 | @implementation UIColor (i7HexColor) 13 | 14 | + (UIColor *)colorWithHexString:(NSString *)hexString { 15 | 16 | /* convert the string into a int */ 17 | unsigned int colorValueR,colorValueG,colorValueB,colorValueA; 18 | NSString *hexStringCleared = [hexString stringByReplacingOccurrencesOfString:@"#" withString:@""]; 19 | if(hexStringCleared.length == 3) { 20 | /* short color form */ 21 | /* im lazy, maybe you have a better idea to convert from #fff to #ffffff */ 22 | hexStringCleared = [NSString stringWithFormat:@"%@%@%@%@%@%@", [hexStringCleared substringWithRange:NSMakeRange(0, 1)],[hexStringCleared substringWithRange:NSMakeRange(0, 1)], 23 | [hexStringCleared substringWithRange:NSMakeRange(1, 1)],[hexStringCleared substringWithRange:NSMakeRange(1, 1)], 24 | [hexStringCleared substringWithRange:NSMakeRange(2, 1)],[hexStringCleared substringWithRange:NSMakeRange(2, 1)]]; 25 | } 26 | if(hexStringCleared.length == 6) { 27 | hexStringCleared = [hexStringCleared stringByAppendingString:@"ff"]; 28 | } 29 | 30 | /* im in hurry ;) */ 31 | NSString *red = [hexStringCleared substringWithRange:NSMakeRange(0, 2)]; 32 | NSString *green = [hexStringCleared substringWithRange:NSMakeRange(2, 2)]; 33 | NSString *blue = [hexStringCleared substringWithRange:NSMakeRange(4, 2)]; 34 | NSString *alpha = [hexStringCleared substringWithRange:NSMakeRange(6, 2)]; 35 | 36 | [[NSScanner scannerWithString:red] scanHexInt:&colorValueR]; 37 | [[NSScanner scannerWithString:green] scanHexInt:&colorValueG]; 38 | [[NSScanner scannerWithString:blue] scanHexInt:&colorValueB]; 39 | [[NSScanner scannerWithString:alpha] scanHexInt:&colorValueA]; 40 | 41 | 42 | return [UIColor colorWithRed:((colorValueR)&0xFF)/255.0 43 | green:((colorValueG)&0xFF)/255.0 44 | blue:((colorValueB)&0xFF)/255.0 45 | alpha:((colorValueA)&0xFF)/255.0]; 46 | 47 | 48 | } 49 | 50 | @end 51 | --------------------------------------------------------------------------------