ios - 如何在 native react 中使用本地镜像?
<p><p>如 <a href="http://ryanclark.me/going-native-with-react/" rel="noreferrer noopener nofollow">this Tutorial</a> 中所述,很容易将本地存储的图像添加到 TabItem(或任何组件):</p>
<ol>
<li>将 XCode 中的图像添加到 images.xcassets</li>
<li>要求它像这样“icon={require('image!pencil')}”(图片的名称是“pencil”)</li>
</ol>
<p>然后我得到的是 iOS 模拟器中的一个异常,带有以下文本:</p>
<blockquote>
<p>Requiring unknown module "image!pencil". If you are sure the module is
there, try restarting the packager</p>
</blockquote>
<p>这里有什么问题?教程?还是 react native 改完了?</p>
<p>代码:</p>
<pre><code>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>
);
}
</code></pre>
<p>}</p>
<p> <a href="/image/pVjil.png" rel="noreferrer noopener nofollow"><img src="/image/pVjil.png" alt="The images-assets"/></a> </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>文件名必须与 images.xcassets 中的资源名称完全相同。</p>
<p>例如,当您添加一个名为“foobar”的新图像集时,分配给该集的所有图像都必须命名为“foobar.png”。
如果您正在使用例如Glyphishpro-Images,图像文件以数字为前缀。如果您随后将这些图像重命名为没有该编号的名称,您将得到这个错误!</p>
<p>我在前几天遇到了这个问题...也是你的问题吗?</p></p>
<p style="font-size: 20px;">关于ios - 如何在 nativereact 中使用本地镜像?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/33189305/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/33189305/
</a>
</p>
页:
[1]