Skip to content

Commit

Permalink
[css] add support for setting UILabel.highlightedTextColor with an -i…
Browse files Browse the repository at this point in the history
…os-highlighted-color property
  • Loading branch information
francisli committed Nov 14, 2012
1 parent 4a8d089 commit 5d85ffa
Show file tree
Hide file tree
Showing 3 changed files with 25 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/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 5d85ffa

Please sign in to comment.