Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[iOS] fix text color error
Browse files Browse the repository at this point in the history
  • Loading branch information
jianhan-he committed Feb 14, 2019
1 parent 3e8cd4a commit a2a58f7
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions ios/sdk/WeexSDK/Sources/Component/WXTextComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ - (instancetype)initWithRef:(NSString *)ref
_useCoreTextAttr = nil;
}

_color[0] = -1.0;

[self fillCSSStyles:styles];
[self fillAttributes:attributes];

Expand Down Expand Up @@ -256,20 +258,24 @@ - (void)fillCSSStyles:(NSDictionary *)styles
WX_STYLE_FILL_TEXT_PIXEL(letterSpacing, letterSpacing, YES)
WX_STYLE_FILL_TEXT(wordWrap, wordWrap, NSString, YES);

UIColor* color = [UIColor blackColor];
UIColor* color = nil;
id value = styles[@"color"];
if (value) {
if(![WXUtility isBlankString:value]){
if([WXUtility isBlankString:value]){
color = [UIColor blackColor];
} else {
color = [WXConvert UIColor:value];
}
[self setNeedsRepaint];
if (color) {
[self setNeedsRepaint];
CGFloat red, green, blue, alpha;
[color getRed:&red green:&green blue:&blue alpha:&alpha];
_color[0] = red;
_color[1] = green;
_color[2] = blue;
_color[3] = alpha;
}
}
CGFloat red, green, blue, alpha;
[color getRed:&red green:&green blue:&blue alpha:&alpha];
_color[0] = red;
_color[1] = green;
_color[2] = blue;
_color[3] = alpha;

if (_fontFamily && !_observerIconfont) {
// notification received when custom icon font file download finish
Expand Down Expand Up @@ -489,7 +495,9 @@ - (NSMutableAttributedString *)buildCTAttributeString
string = @"";
}
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString: string];
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:_color[0] green:_color[1] blue:_color[2] alpha:_color[3]] range:NSMakeRange(0, string.length)];
if (_color[0] >= 0) {
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:_color[0] green:_color[1] blue:_color[2] alpha:_color[3]] range:NSMakeRange(0, string.length)];
}

// set font
UIFont *font = [WXUtility fontWithSize:_fontSize textWeight:_fontWeight textStyle:_fontStyle fontFamily:_fontFamily scaleFactor:self.weexInstance.pixelScaleFactor useCoreText:[self useCoreText]];
Expand Down Expand Up @@ -579,7 +587,9 @@ - (NSAttributedString *)buildAttributeString
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];

// set textColor
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:_color[0] green:_color[1] blue:_color[2] alpha:_color[3]] range:NSMakeRange(0, string.length)];
if (_color[0] >= 0) {
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:_color[0] green:_color[1] blue:_color[2] alpha:_color[3]] range:NSMakeRange(0, string.length)];
}

// set font
UIFont *font = [WXUtility fontWithSize:_fontSize textWeight:_fontWeight textStyle:_fontStyle fontFamily:_fontFamily scaleFactor:self.weexInstance.pixelScaleFactor];
Expand Down

0 comments on commit a2a58f7

Please sign in to comment.