在CSS中,filter属性可用于配置图像的亮度,如
// using CSS
filter: brightness(50%);
如何在React Native Images中获得相同的结果?
答案 0 :(得分:4)
JSX:
<Image style={styles.universityImage} source={require('./csun.jpg')}>
<View style={styles.innerFrame}>
<Text style={styles.universityName}>California State University, Northridge</Text>
<Text style={styles.universityMotto}>"CSUN Shine"</Text>
</View>
</Image>
样式表:
const styles = StyleSheet.create({
// View tag styling
innerFrame: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'rgba(0, 0, 0, .5)',
},
// Image tag styling
universityImage: {
width: 300,
height: 250,
borderRadius: 5,
},
universityName: {
color: '#fff',
opacity: .9,
fontSize: 20,
textAlign: 'center',
fontWeight: '500',
marginVertical: 15,
backgroundColor: 'transparent'
},
universityMotto: {
color: '#fff',
opacity: .9,
textAlign: 'center',
backgroundColor: 'transparent'
}
})
在<View></View>
中嵌套<Image></Image>
标记并提供视图标记flex: 1
,以便它占用父标记的整个宽度和高度,即{{1}在这种情况下标记。然后在<Image></Image>
标记中添加backgroundColor: rbga(0, 0, 0, .5)
,使其具有不透明的外观。那就是它!希望这可以帮助别人!
P.S。在嵌套的<View></View>
标记内,我提供了<View></View>
,以便文字完全位于中间
答案 1 :(得分:0)
React native的CSS支持有限,但请查看此repo:https://github.com/stoffern/gl-react-instagramfilters这可能有助于您继续使用。
答案 2 :(得分:0)