From 345e839d32926d5423cfaba7137db300e2a26dc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Tue, 17 Jan 2023 11:18:15 +0800 Subject: [PATCH] iOS: font style for input --- doric-iOS/Pod/Classes/Shader/DoricInputNode.m | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/doric-iOS/Pod/Classes/Shader/DoricInputNode.m b/doric-iOS/Pod/Classes/Shader/DoricInputNode.m index b4013fc6..b4dfc03c 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricInputNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricInputNode.m @@ -304,6 +304,7 @@ @interface DoricInputNode () @property(nonatomic, copy) onSubmitEditingBlock onSubmitEditing; @property(nonatomic, strong) NSNumber *maxLength; @property(nonatomic, copy) NSString *beforeTextChangeFuncId; +@property(nonatomic, assign) BOOL customizedFont; @end @implementation DoricInputNode @@ -350,11 +351,36 @@ - (void)blendView:(DoricInputView *)view forPropName:(NSString *)name propValue: verticalAlignment = UIControlContentVerticalAlignmentBottom; } view.singleLineInput.contentVerticalAlignment = verticalAlignment; + } else if ([name isEqualToString:@"fontStyle"]) { + UIFont *font = view.font; + if (!font) { + font = [UIFont systemFontOfSize:[UIFont systemFontSize]]; + } + UIFontDescriptor *fontDescriptor = nil; + if ([@"bold" isEqualToString:prop]) { + fontDescriptor = [font.fontDescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold]; + } else if ([@"italic" isEqualToString:prop]) { + fontDescriptor = [font.fontDescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitItalic]; + } else if ([@"bold_italic" isEqualToString:prop]) { + fontDescriptor = [font.fontDescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold | UIFontDescriptorTraitItalic]; + } + if (fontDescriptor) { + font = [UIFont fontWithDescriptor:fontDescriptor size:0]; + } else { + 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:@"font"]) { NSString *iconfont = prop; UIFont *font = [UIFont fontWithName:[iconfont stringByReplacingOccurrencesOfString:@".ttf" withString:@""] size:view.font.pointSize]; view.font = font; + self.customizedFont = YES; } else if ([name isEqualToString:@"multiline"]) { BOOL value = [(NSNumber *) prop boolValue]; view.multiline = value; @@ -689,5 +715,6 @@ - (void)reset { self.onSubmitEditing = nil; self.onTextChange = nil; self.maxLength = nil; + self.customizedFont = NO; } @end