Den*_*Hiu 5 react-native react-native-stylesheet
我有一个这样的图像作为资产seats.png(180 x 36 像素),每个“座位”是一个 36x36 像素的图像:
我的代码:
<View style={styles.container}>
<ImageBackground
style={styles.redSeat}
source={seatsPng}
resizeMode="cover"
>
</ImageBackground>
</View>
import EStyleSheet from 'react-native-extended-stylesheet';
export default EStyleSheet.create({
container: {
backgroundColor: '#333',
paddingTop: 10,
paddingBottom: 10,
paddingLeft: 10,
paddingRight: 10,
},
redSeat: {
width: 36,
height: 36,
left: 0 // I want to show only red seat on the display
}
});
Run Code Online (Sandbox Code Playgroud)
如何使它可以显示红色座位、黄色座位或紫色座位,只需调整图像偏移量,如 HTML/CSS 中的背景位置?上面的代码只显示一个绿色的座位。
PS:我搜索了 React-native GitHub 页面,我不敢相信这个问题被标记为关闭而开发人员没有解决方案。因此,如果将来可能有解决方案,我将打开此线程。https://github.com/facebook/react-native/issues/12347
| 归档时间: |
|
| 查看次数: |
1126 次 |
| 最近记录: |