gpt4 book ai didi

ios - 如何在 React Native 中为 使用自定义字体?

转载 作者:行者123 更新时间:2023-11-29 00:54:42 29 4
gpt4 key购买 nike

我正在使用 <TabBarIOS>组件,我有自定义图标工作(使用 react-native-vector-icons )但是我正在努力获得自定义 fontFamily<Icon.TabBarItemIOS> 上成分。我希望能够更改每个图标下方文本标签的字体。

我已经尝试将样式添加到选项卡栏和选项卡栏项目,但它返回错误:

2016-06-09 17:45:52.449 [warn][tid:com.facebook.react.JavaScript] Warning: Failed propType: Invalid props.style key `fontFamily` supplied to `RCTTabBar`.
Bad object: {
"flex": 1,
"fontFamily": "Roboto-Regular"
}
Valid keys: [
"width",
"height",
"top",
"left",
"right",
"bottom",
"margin",
"marginVertical",
"marginHorizontal",
"marginTop",
"marginBottom",
"marginLeft",
"marginRight",
"padding",
"paddingVertical",
"paddingHorizontal",
"paddingTop",
"paddingBottom",
"paddingLeft",
"paddingRight",
"borderWidth",
"borderTopWidth",
"borderRightWidth",
"borderBottomWidth",
"borderLeftWidth",
"position",
"flexDirection",
"flexWrap",
"justifyContent",
"alignItems",
"alignSelf",
"flex",
"shadowColor",
"shadowOffset",
"shadowOpacity",
"shadowRadius",
"transform",
"transformMatrix",
"decomposedMatrix",
"scaleX",
"scaleY",
"rotation",
"translateX",
"translateY",
"backfaceVisibility",
"backgroundColor",
"borderColor",
"borderTopColor",
"borderRightColor",
"borderBottomColor",
"borderLeftColor",
"borderRadius",
"borderTopLeftRadius",
"borderTopRightRadius",
"borderBottomLeftRadius",
"borderBottomRightRadius",
"borderStyle",
"opacity",
"overflow",
"elevation"
] Check the render method of `TabBarIOS`.

我已经查看了文档,但找不到关于这个主题的任何内容,有什么想法吗?

最佳答案

如果您想调整字体,您需要修改 Objective-C 桥。例如,在 RCTTabBarItem.m 中,您有以下设置代码。您可以使用 setTitleTextAttributes 来指定您的字体。

- (void)setIcon:(UIImage *)icon
{
_icon = icon;
if (_icon && _systemIcon != NSNotFound) {
_systemIcon = NSNotFound;
UITabBarItem *oldItem = _barItem;
_barItem = [UITabBarItem new];
_barItem.title = oldItem.title;
_barItem.imageInsets = oldItem.imageInsets;
_barItem.selectedImage = oldItem.selectedImage;
_barItem.badgeValue = oldItem.badgeValue;
}

/* set custom font for tabBarItem */
[_barItem setTitleTextAttributes:@{
NSFontAttributeName: [UIFont fontWithName:@"Raleway-Bold" size:10.0f]
} forState:UIControlStateSelected];
[_barItem setTitleTextAttributes:@{
NSFontAttributeName: [UIFont fontWithName:@"Raleway-Bold" size:10.0f]
} forState:UIControlStateNormal];

if (_renderAsOriginal) {
self.barItem.image = [_icon imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
} else {
self.barItem.image = _icon;
}
}

关于ios - 如何在 React Native 中为 <TabBarIOS> 使用自定义字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37730764/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com