Skip to content

Commit

Permalink
Merge pull request jverkoey#309 from francisli/submissions
Browse files Browse the repository at this point in the history
[css] add support for setting highlightedTextColor on UILabel with Nimbus CSS
  • Loading branch information
jverkoey committed Nov 14, 2012
2 parents 4a8d089 + bb90c20 commit bc116ce
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/css/src/NICSSRuleset.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
NSMutableDictionary* _ruleset;

UIColor* _textColor;
UIColor* _highlightedTextColor;
UITextAlignment _textAlignment;
UIFont* _font;
UIColor* _textShadowColor;
Expand All @@ -54,6 +55,7 @@
union {
struct {
int TextColor : 1;
int HighlightedTextColor: 1;
int TextAlignment : 1;
int Font : 1;
int TextShadowColor : 1;
Expand Down Expand Up @@ -83,6 +85,9 @@
- (BOOL)hasTextColor;
- (UIColor *)textColor; // color

- (BOOL)hasHighlightedTextColor;
- (UIColor *)highlightedTextColor;

- (BOOL)hasTextAlignment;
- (UITextAlignment)textAlignment; // text-align

Expand Down
19 changes: 19 additions & 0 deletions src/css/src/NICSSRuleset.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#endif

static NSString* const kTextColorKey = @"color";
static NSString* const kHighlightedTextColorKey = @"-ios-highlighted-color";
static NSString* const kTextAlignmentKey = @"text-align";
static NSString* const kFontKey = @"font";
static NSString* const kFontSizeKey = @"font-size";
Expand Down Expand Up @@ -121,6 +122,24 @@ - (UIColor *)textColor {
}


///////////////////////////////////////////////////////////////////////////////////////////////////
- (BOOL)hasHighlightedTextColor {
return nil != [_ruleset objectForKey:kHighlightedTextColorKey];
}


///////////////////////////////////////////////////////////////////////////////////////////////////
- (UIColor *)highlightedTextColor {
NIDASSERT([self hasHighlightedTextColor]);
if (!_is.cached.HighlightedTextColor) {
_highlightedTextColor = [[self class] colorFromCssValues:[_ruleset objectForKey:kHighlightedTextColorKey]
numberOfConsumedTokens:nil];
_is.cached.HighlightedTextColor = YES;
}
return _highlightedTextColor;
}


///////////////////////////////////////////////////////////////////////////////////////////////////
- (BOOL)hasTextAlignment {
return nil != [_ruleset objectForKey:kTextAlignmentKey];
Expand Down
1 change: 1 addition & 0 deletions src/css/src/NimbusCSS.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ UILabel {
text-shadow: <color> <x-offset> <y-offset> {label.shadowColor label.shadowOffset}
-ios-highlighted-color: <color> {label.highlightedTextColor}
-ios-line-break-mode: [wrap|character-wrap|clip|head-truncate|tail-truncate|middle-truncate] [label.lineBreakMode]
-ios-number-of-lines: xx {label.numberOfLines}
-ios-minimum-font-size: <font-size> {label.minimumFontSize}
Expand Down
1 change: 1 addition & 0 deletions src/css/src/UILabel+NIStyleable.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ @implementation UILabel (NIStyleable)
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)applyLabelStyleWithRuleSet:(NICSSRuleset *)ruleSet {
if ([ruleSet hasTextColor]) { self.textColor = ruleSet.textColor; }
if ([ruleSet hasHighlightedTextColor]) { self.highlightedTextColor = ruleSet.highlightedTextColor; }
if ([ruleSet hasTextAlignment]) { self.textAlignment = ruleSet.textAlignment; }
if ([ruleSet hasFont]) { self.font = ruleSet.font; }
if ([ruleSet hasTextShadowColor]) { self.shadowColor = ruleSet.textShadowColor; }
Expand Down

0 comments on commit bc116ce

Please sign in to comment.