ios - 使用 React Native,尝试使用背景图片时出现错误

标签 ios react-native

我相信这可能与我存储图像的位置有关。它们可以在 ../ProjectName/img/fileName.png 中找到 我需要做些什么来加载文件以便可以访问它们吗?

 <View style={styles.container}>
                <HomeHeaderTitle isHomePage={true}/>
                <View style={styles.quoteContainer}>
                  <Image source={require('../../img/backgroundQuote3.png')} />
                </View>
            </View>

当我将上面的代码添加到我的代码中时,它给了我这个错误:

enter image description here

react-native-cli: 2.0.1
react-native: 0.39.0

最佳答案

我看到了你的问题。您应该在一个级别上阅读源图像吗?

例如:

<Image source={require('../img/backgroundQuote3.png')} />

另外,当你想使用背景图片时,是否应该使用element is parent view?

例如:

 <Image source={require('../img/backgroundQuote3.png')}> 
    <View>
    </View>
</Image>

加油!

PS:别忘了投票!

关于ios - 使用 React Native,尝试使用背景图片时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41621562/

相关文章:

ios - 如何在 iOS 应用程序中播放播客文件

ios - 如何在 Xcode 的 AppDelegate.h 中声明接口(interface)?

javascript - 在 react-native 上看不到嵌入 youtube

c++ - NSMutableArray 到 std::vector

ios - 如何使长文本易于访问

php - iOS 推送通知我做错了什么?

ios - React Native 复选框显示为红点

ios - 当检查 nil 时,Swift Optional 有时会在设备上崩溃,但不会在模拟器上崩溃

javascript - React Native 无限滚动

ruby - 在 m1 mac 上安装 Hermes 引擎时出现 pod 安装问题