OGeek|极客世界-中国程序员成长平台

标题: ios - 如何在 native react 中使用本地镜像? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 09:22
标题: ios - 如何在 native react 中使用本地镜像?

this Tutorial 中所述,很容易将本地存储的图像添加到 TabItem(或任何组件):

  1. 将 XCode 中的图像添加到 images.xcassets
  2. 要求它像这样“icon={require('image!pencil')}”(图片的名称是“pencil”)

然后我得到的是 iOS 模拟器中的一个异常,带有以下文本:

Requiring unknown module "image!pencil". If you are sure the module is there, try restarting the packager

这里有什么问题?教程?还是 react native 改完了?

代码:

class devdactic_tabs extends Component {

constructor(props) {
    super(props);
    this.state = {
        selectedTab: 'welcome'
    };
}

render() {
    return (
        <TabBarIOS selectedTab={this.state.selectedTab}>
            <TabBarIOS.Item
                selected={this.state.selectedTab === 'welcome'}
                icon={require('image!pencil')}
                onPress={() => {
          this.setState({
              selectedTab: 'welcome',
          });
      }}>
                <Welcome/>
            </TabBarIOS.Item>
            <TabBarIOS.Item
                selected={this.state.selectedTab === 'more'}
                systemIcon="contacts"
                onPress={() => {
            this.setState({
                selectedTab: 'more',
            });
      }}>
                <More/>
            </TabBarIOS.Item>
        </TabBarIOS>
    );
}

}

The images-assets



Best Answer-推荐答案


文件名必须与 images.xcassets 中的资源名称完全相同。

例如,当您添加一个名为“foobar”的新图像集时,分配给该集的所有图像都必须命名为“foobar.png”。 如果您正在使用例如Glyphishpro-Images,图像文件以数字为前缀。如果您随后将这些图像重命名为没有该编号的名称,您将得到这个错误!

我在前几天遇到了这个问题...也是你的问题吗?

关于ios - 如何在 native react 中使用本地镜像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33189305/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4