From 956cf7583e494bee1872e55079ddf0f4b7812a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Fri, 13 Jan 2023 11:50:44 +0800 Subject: [PATCH] iOS: fix font style cannot change from system bold to system normal --- doric-iOS/Pod/Classes/Shader/DoricTextNode.m | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/doric-iOS/Pod/Classes/Shader/DoricTextNode.m b/doric-iOS/Pod/Classes/Shader/DoricTextNode.m index 0d4cb69c..27058e63 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricTextNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricTextNode.m @@ -64,6 +64,7 @@ @interface DoricTextNode () @property(nonatomic, copy) NSNumber *strikethrough; @property(nonatomic, strong) NSDictionary *textGradientProps; @property(nonatomic, assign) CGSize textGradientSize; +@property(nonatomic, assign) BOOL customizedFont; @end @implementation DoricTextNode @@ -130,7 +131,12 @@ - (void)blendView:(UILabel *)view forPropName:(NSString *)name propValue:(id)pro if (fontDescriptor) { font = [UIFont fontWithDescriptor:fontDescriptor size:0]; } else { - font = [UIFont fontWithName:font.fontName size:font.pointSize]; + if (self.customizedFont) { + font = [UIFont fontWithName:font.fontName size:font.pointSize]; + } else { + UIFont *systemFont = [UIFont systemFontOfSize:[UIFont systemFontSize]]; + font = [UIFont fontWithName:systemFont.fontName size:font.pointSize]; + } } view.font = font; } else if ([name isEqualToString:@"maxWidth"]) { @@ -143,6 +149,7 @@ - (void)blendView:(UILabel *)view forPropName:(NSString *)name propValue:(id)pro UIFont *font = [UIFont fontWithName:[iconfont stringByReplacingOccurrencesOfString:@".ttf" withString:@""] size:view.font.pointSize]; view.font = font; + self.customizedFont = YES; } else if ([prop isKindOfClass:[NSDictionary class]]) { DoricAsyncResult *asyncResult = [[self.doricContext.driver.registry.loaderManager load:prop @@ -150,6 +157,7 @@ - (void)blendView:(UILabel *)view forPropName:(NSString *)name propValue:(id)pro [asyncResult setResultCallback:^(NSData *fontData) { [self.doricContext dispatchToMainQueue:^{ view.font = [self registerFontWithFontData:fontData fontSize:view.font.pointSize]; + self.customizedFont = YES; }]; }]; [asyncResult setExceptionCallback:^(NSException *e) { @@ -391,5 +399,6 @@ - (void)reset { self.view.layer.shadowRadius = 3; self.view.layer.shadowOffset = CGSizeMake(0, -3); self.view.lineBreakMode = NSLineBreakByTruncatingTail; + self.customizedFont = NO; } @end