iOS: font style for input

This commit is contained in:
王劲鹏 2023-01-17 11:18:15 +08:00 committed by osborn
parent f7d9655213
commit 345e839d32

View File

@ -304,6 +304,7 @@ @interface DoricInputNode () <UITextViewDelegate, UITextFieldDelegate>
@property(nonatomic, copy) onSubmitEditingBlock onSubmitEditing; @property(nonatomic, copy) onSubmitEditingBlock onSubmitEditing;
@property(nonatomic, strong) NSNumber *maxLength; @property(nonatomic, strong) NSNumber *maxLength;
@property(nonatomic, copy) NSString *beforeTextChangeFuncId; @property(nonatomic, copy) NSString *beforeTextChangeFuncId;
@property(nonatomic, assign) BOOL customizedFont;
@end @end
@implementation DoricInputNode @implementation DoricInputNode
@ -350,11 +351,36 @@ - (void)blendView:(DoricInputView *)view forPropName:(NSString *)name propValue:
verticalAlignment = UIControlContentVerticalAlignmentBottom; verticalAlignment = UIControlContentVerticalAlignmentBottom;
} }
view.singleLineInput.contentVerticalAlignment = verticalAlignment; 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"]) { } else if ([name isEqualToString:@"font"]) {
NSString *iconfont = prop; NSString *iconfont = prop;
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 ([name isEqualToString:@"multiline"]) { } else if ([name isEqualToString:@"multiline"]) {
BOOL value = [(NSNumber *) prop boolValue]; BOOL value = [(NSNumber *) prop boolValue];
view.multiline = value; view.multiline = value;
@ -689,5 +715,6 @@ - (void)reset {
self.onSubmitEditing = nil; self.onSubmitEditing = nil;
self.onTextChange = nil; self.onTextChange = nil;
self.maxLength = nil; self.maxLength = nil;
self.customizedFont = NO;
} }
@end @end