diff --git a/doric-demo/bundle/DINPro.ttf b/doric-demo/bundle/DINPro.ttf new file mode 100644 index 00000000..84d57abb Binary files /dev/null and b/doric-demo/bundle/DINPro.ttf differ diff --git a/doric-demo/bundle/Hanabi.ttf b/doric-demo/bundle/Hanabi.ttf new file mode 100644 index 00000000..c68dbbbf Binary files /dev/null and b/doric-demo/bundle/Hanabi.ttf differ diff --git a/doric-demo/src/InputDemo.ts b/doric-demo/src/InputDemo.ts index 9ed5333d..8ec03b5c 100644 --- a/doric-demo/src/InputDemo.ts +++ b/doric-demo/src/InputDemo.ts @@ -99,6 +99,10 @@ class InputDemo extends Panel { width: 1, color: Color.GRAY, }, + font: 'DINPro', + hintFont: 'Hanabi', + textColor: Color.RED, + hintTextColor: Color.GREEN, }), ], { diff --git a/doric-iOS/Example/Example.xcodeproj/project.pbxproj b/doric-iOS/Example/Example.xcodeproj/project.pbxproj index aa0537f8..2e1c5d1e 100644 --- a/doric-iOS/Example/Example.xcodeproj/project.pbxproj +++ b/doric-iOS/Example/Example.xcodeproj/project.pbxproj @@ -11,6 +11,8 @@ 1BCA4753C9D35032A0288028 /* libPods-ExampleUITests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD2D6CCC8DCDABA7F86EAE7C /* libPods-ExampleUITests.a */; }; 52F56220E3A039DD5E3EA3B2 /* libPods-Example.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4650C6577493F533466F084B /* libPods-Example.a */; }; 8B429D94241B66A300572570 /* iconfont.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 8B429D93241B66A200572570 /* iconfont.ttf */; }; + 8B5E51F126A6B68E00D06220 /* Hanabi.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 8B5E51F026A6B68900D06220 /* Hanabi.ttf */; }; + 8B71685F26A5AF0E0087291A /* DINPro.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 8B71685E26A5AE9A0087291A /* DINPro.ttf */; }; 8BCADA7C23CD5B65005EEF96 /* NavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BCADA7B23CD5B64005EEF96 /* NavigationController.m */; }; D751D4B065D8D4FA6594B5EE /* DemoVC.m in Sources */ = {isa = PBXBuildFile; fileRef = D751D19E97EF4EDD7588FEBE /* DemoVC.m */; }; D751DDB012BAF476A252CD93 /* DemoLibrary.m in Sources */ = {isa = PBXBuildFile; fileRef = D751D2175D09F2C10691FB81 /* DemoLibrary.m */; }; @@ -49,6 +51,8 @@ 8231E841CCAF382F85C9F576 /* Pods-Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Example/Pods-Example.debug.xcconfig"; sourceTree = ""; }; 8A68295410FE7498FAFBB726 /* libPods-ExampleTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ExampleTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 8B429D93241B66A200572570 /* iconfont.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = iconfont.ttf; path = "../../../doric-demo/bundle/iconfont.ttf"; sourceTree = ""; }; + 8B5E51F026A6B68900D06220 /* Hanabi.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = Hanabi.ttf; path = "../../../doric-demo/bundle/Hanabi.ttf"; sourceTree = ""; }; + 8B71685E26A5AE9A0087291A /* DINPro.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = DINPro.ttf; path = "../../../doric-demo/bundle/DINPro.ttf"; sourceTree = ""; }; 8BCADA7A23CD5B5F005EEF96 /* NavigationController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NavigationController.h; sourceTree = ""; }; 8BCADA7B23CD5B64005EEF96 /* NavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NavigationController.m; sourceTree = ""; }; B93423722F2E06DC238CDD18 /* Pods-ExampleUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ExampleUITests.release.xcconfig"; path = "Pods/Target Support Files/Pods-ExampleUITests/Pods-ExampleUITests.release.xcconfig"; sourceTree = ""; }; @@ -154,6 +158,8 @@ E2334AED22E9D2060098A085 /* Example */ = { isa = PBXGroup; children = ( + 8B71685E26A5AE9A0087291A /* DINPro.ttf */, + 8B5E51F026A6B68900D06220 /* Hanabi.ttf */, 8B429D93241B66A200572570 /* iconfont.ttf */, E2C9315823B0A263007933D9 /* src */, E2334AEE22E9D2060098A085 /* AppDelegate.h */, @@ -302,6 +308,8 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 8B5E51F126A6B68E00D06220 /* Hanabi.ttf in Resources */, + 8B71685F26A5AF0E0087291A /* DINPro.ttf in Resources */, E2334AFB22E9D2070098A085 /* LaunchScreen.storyboard in Resources */, E2334AF822E9D2070098A085 /* Assets.xcassets in Resources */, E2334AF622E9D2060098A085 /* Main.storyboard in Resources */, diff --git a/doric-iOS/Example/Example/AppDelegate.m b/doric-iOS/Example/Example/AppDelegate.m index 429f2a4e..43165a66 100644 --- a/doric-iOS/Example/Example/AppDelegate.m +++ b/doric-iOS/Example/Example/AppDelegate.m @@ -35,6 +35,7 @@ - (void)localeChanged { - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. + NSArray *fonts = [UIFont familyNames]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(localeChanged) diff --git a/doric-iOS/Example/Example/Info.plist b/doric-iOS/Example/Example/Info.plist index 2188fc7a..b3939149 100644 --- a/doric-iOS/Example/Example/Info.plist +++ b/doric-iOS/Example/Example/Info.plist @@ -29,6 +29,8 @@ Scan QR Code UIAppFonts + DINPro.ttf + Hanabi.ttf iconfont.ttf UILaunchStoryboardName diff --git a/doric-iOS/Pod/Classes/Shader/DoricInputNode.m b/doric-iOS/Pod/Classes/Shader/DoricInputNode.m index f3d03c2a..7afdaba3 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricInputNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricInputNode.m @@ -102,7 +102,12 @@ - (void)blendView:(DoricInputView *)view forPropName:(NSString *)name propValue: if ([name isEqualToString:@"text"]) { view.text = prop; } else if ([name isEqualToString:@"textSize"]) { - view.font = [UIFont systemFontOfSize:[(NSNumber *) prop floatValue]]; + UIFont *font = view.font; + if (font) { + view.font = [view.font fontWithSize:[(NSNumber *) prop floatValue]]; + } else { + view.font = [UIFont systemFontOfSize:[(NSNumber *) prop floatValue]]; + } } else if ([name isEqualToString:@"textColor"]) { view.textColor = DoricColor(prop); } else if ([name isEqualToString:@"textAlignment"]) { @@ -115,6 +120,11 @@ - (void)blendView:(DoricInputView *)view forPropName:(NSString *)name propValue: } view.textAlignment = alignment; view.placeholderLabel.textAlignment = alignment; + } else if ([name isEqualToString:@"font"]) { + NSString *iconfont = prop; + UIFont *font = [UIFont fontWithName:[iconfont stringByReplacingOccurrencesOfString:@".ttf" withString:@""] + size:view.font.pointSize]; + view.font = font; } else if ([name isEqualToString:@"multiline"]) { BOOL value = [(NSNumber *) prop boolValue]; if (!value) { @@ -131,6 +141,11 @@ - (void)blendView:(DoricInputView *)view forPropName:(NSString *)name propValue: view.placeholderLabel.text = (NSString *) prop; } else if ([name isEqualToString:@"hintTextColor"]) { view.placeholderLabel.textColor = DoricColor(prop); + } else if ([name isEqualToString:@"hintFont"]) { + NSString *iconfont = prop; + UIFont *font = [UIFont fontWithName:[iconfont stringByReplacingOccurrencesOfString:@".ttf" withString:@""] + size:view.font.pointSize]; + view.placeholderLabel.font = font; } else if ([name isEqualToString:@"onTextChange"]) { if ([prop isKindOfClass:[NSString class]]) { self.onTextChange = ^(NSString *text, DoricInputNode *node) { @@ -227,7 +242,14 @@ - (void)afterBlended:(NSDictionary *)props { || self.view.doricLayout.paddingRight != self.view.textContainerInset.right) { self.view.textContainerInset = UIEdgeInsetsMake(self.view.doricLayout.paddingTop, self.view.doricLayout.paddingLeft, self.view.doricLayout.paddingBottom, self.view.doricLayout.paddingRight); } - self.view.placeholderLabel.font = self.view.font; + + UIFont *font = self.view.placeholderLabel.font; + if (font) { + self.view.placeholderLabel.font = [self.view.placeholderLabel.font fontWithSize:self.view.font.pointSize]; + } else { + self.view.placeholderLabel.font = self.view.font; + } + self.view.placeholderLabel.numberOfLines = self.view.textContainer.maximumNumberOfLines; }