forked from mobilehub/CoreTextToy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the ability to use <font color="#AABBFF">text</font> style tags…
… to color text dynamically without having to set a markup style tag. Useful for dynamic text loaded through network. Uses UIColor+Hex category, which I did NOT write, but the snippet was found long ago, and don't recall where, else I would attribute it.
- Loading branch information
1 parent
9009c2f
commit ded73cb
Showing
7 changed files
with
102 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,15 @@ | |||
// | |||
// UIColor+Hex.h | |||
// CultureShelf | |||
// | |||
// Created by Daniel Wyszynski on 11/1/11. | |||
// Copyright (c) 2011 Punch Media, Inc. All rights reserved. | |||
// | |||
|
|||
#import <Foundation/Foundation.h> | |||
|
|||
@interface UIColor (i7HexColor) | |||
|
|||
+ (UIColor *)colorWithHexString:(NSString *)hexString; | |||
|
|||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,49 @@ | |||
// | |||
// UIColor+Hex.m | |||
// CultureShelf | |||
// | |||
// Created by Daniel Wyszynski on 11/1/11. | |||
// Copyright (c) 2011 Punch Media, Inc. All rights reserved. | |||
// | |||
|
|||
#import "UIColor+Hex.h" | |||
|
|||
@implementation UIColor (i7HexColor) | |||
|
|||
+ (UIColor *)colorWithHexString:(NSString *)hexString { | |||
|
|||
/* convert the string into a int */ | |||
unsigned int colorValueR,colorValueG,colorValueB,colorValueA; | |||
NSString *hexStringCleared = [hexString stringByReplacingOccurrencesOfString:@"#" withString:@""]; | |||
if(hexStringCleared.length == 3) { | |||
/* short color form */ | |||
/* im lazy, maybe you have a better idea to convert from #fff to #ffffff */ | |||
hexStringCleared = [NSString stringWithFormat:@"%@%@%@%@%@%@", [hexStringCleared substringWithRange:NSMakeRange(0, 1)],[hexStringCleared substringWithRange:NSMakeRange(0, 1)], | |||
[hexStringCleared substringWithRange:NSMakeRange(1, 1)],[hexStringCleared substringWithRange:NSMakeRange(1, 1)], | |||
[hexStringCleared substringWithRange:NSMakeRange(2, 1)],[hexStringCleared substringWithRange:NSMakeRange(2, 1)]]; | |||
} | |||
if(hexStringCleared.length == 6) { | |||
hexStringCleared = [hexStringCleared stringByAppendingString:@"ff"]; | |||
} | |||
|
|||
/* im in hurry ;) */ | |||
NSString *red = [hexStringCleared substringWithRange:NSMakeRange(0, 2)]; | |||
NSString *green = [hexStringCleared substringWithRange:NSMakeRange(2, 2)]; | |||
NSString *blue = [hexStringCleared substringWithRange:NSMakeRange(4, 2)]; | |||
NSString *alpha = [hexStringCleared substringWithRange:NSMakeRange(6, 2)]; | |||
|
|||
[[NSScanner scannerWithString:red] scanHexInt:&colorValueR]; | |||
[[NSScanner scannerWithString:green] scanHexInt:&colorValueG]; | |||
[[NSScanner scannerWithString:blue] scanHexInt:&colorValueB]; | |||
[[NSScanner scannerWithString:alpha] scanHexInt:&colorValueA]; | |||
|
|||
|
|||
return [UIColor colorWithRed:((colorValueR)&0xFF)/255.0 | |||
green:((colorValueG)&0xFF)/255.0 | |||
blue:((colorValueB)&0xFF)/255.0 | |||
alpha:((colorValueA)&0xFF)/255.0]; | |||
|
|||
|
|||
} | |||
|
|||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters