iOS: fix font style cannot change from system bold to system normal

This commit is contained in:
王劲鹏 2023-01-13 11:50:44 +08:00 committed by osborn
parent a0d4e564c1
commit 956cf7583e

View File

@ -64,6 +64,7 @@ @interface DoricTextNode ()
@property(nonatomic, copy) NSNumber *strikethrough; @property(nonatomic, copy) NSNumber *strikethrough;
@property(nonatomic, strong) NSDictionary *textGradientProps; @property(nonatomic, strong) NSDictionary *textGradientProps;
@property(nonatomic, assign) CGSize textGradientSize; @property(nonatomic, assign) CGSize textGradientSize;
@property(nonatomic, assign) BOOL customizedFont;
@end @end
@implementation DoricTextNode @implementation DoricTextNode
@ -130,7 +131,12 @@ - (void)blendView:(UILabel *)view forPropName:(NSString *)name propValue:(id)pro
if (fontDescriptor) { if (fontDescriptor) {
font = [UIFont fontWithDescriptor:fontDescriptor size:0]; font = [UIFont fontWithDescriptor:fontDescriptor size:0];
} else { } else {
if (self.customizedFont) {
font = [UIFont fontWithName:font.fontName size:font.pointSize]; 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; view.font = font;
} else if ([name isEqualToString:@"maxWidth"]) { } 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:@""] UIFont *font = [UIFont fontWithName:[iconfont stringByReplacingOccurrencesOfString:@".ttf" withString:@""]
size:view.font.pointSize]; size:view.font.pointSize];
view.font = font; view.font = font;
self.customizedFont = YES;
} else if ([prop isKindOfClass:[NSDictionary class]]) { } else if ([prop isKindOfClass:[NSDictionary class]]) {
DoricAsyncResult <NSData *> *asyncResult = [[self.doricContext.driver.registry.loaderManager DoricAsyncResult <NSData *> *asyncResult = [[self.doricContext.driver.registry.loaderManager
load:prop load:prop
@ -150,6 +157,7 @@ - (void)blendView:(UILabel *)view forPropName:(NSString *)name propValue:(id)pro
[asyncResult setResultCallback:^(NSData *fontData) { [asyncResult setResultCallback:^(NSData *fontData) {
[self.doricContext dispatchToMainQueue:^{ [self.doricContext dispatchToMainQueue:^{
view.font = [self registerFontWithFontData:fontData fontSize:view.font.pointSize]; view.font = [self registerFontWithFontData:fontData fontSize:view.font.pointSize];
self.customizedFont = YES;
}]; }];
}]; }];
[asyncResult setExceptionCallback:^(NSException *e) { [asyncResult setExceptionCallback:^(NSException *e) {
@ -391,5 +399,6 @@ - (void)reset {
self.view.layer.shadowRadius = 3; self.view.layer.shadowRadius = 3;
self.view.layer.shadowOffset = CGSizeMake(0, -3); self.view.layer.shadowOffset = CGSizeMake(0, -3);
self.view.lineBreakMode = NSLineBreakByTruncatingTail; self.view.lineBreakMode = NSLineBreakByTruncatingTail;
self.customizedFont = NO;
} }
@end @end