Fur*_*nG. 6 border react-native react-native-stylesheet
如何在图像中制作边框底部半径?
以及如何将图像屏蔽到绿色区域?
我已经尝试了以下代码,但我无法在上面共享的图像中获得半径比
查看代码:
<View style={styles.wrapper}>
<View style={styles.welcomeWrapper}>
<View style={styles.welcomeImageWrapper}>
<Image style={{width:'100%'}} source={require('../assets/images/test-slide.jpg')}/>
</View>
</View>
<View style={{
height: 100,
backgroundColor: colors.white,
justifyContent: 'flex-end',
alignItems: 'center'
}}>
<Text style={{marginBottom:50,fontSize:18,fontFamily:'Montserrat-Regular'}}>Deneme Text </Text>
</View>
</View>
Run Code Online (Sandbox Code Playgroud)
样式代码:
wrapper:{
flex:1,
display: 'flex',
backgroundColor:colors.white,
},
welcomeWrapper:{
flex:1,
justifyContent:'center',
backgroundColor:colors.green01,
overflow: 'hidden',
position:'relative',
width:'100%',
borderBottomRightRadius:Dimensions.get('window').width/100*50,
borderBottomLeftRadius:Dimensions.get('window').width/100*50,
},
Run Code Online (Sandbox Code Playgroud)
Fra*_*rel 11
看到你的图像蒙版的形状,我认为你应该使用类似的东西react-native-svg
来创建一个真实的图像蒙版。
步骤:
View
用 a设置背景图片position: absolute
,这样你的图片总是在背景中并且可以被屏蔽
添加react-native-svg
到您的项目中,例如使用yarn add react-native-svg
,并使用 链接库react-native link
。最后,重新启动 Metro bundler 并编译您的应用程序(run-android
或run-ios
)。
设计 svg 蒙版(我使用了inkscape)并将其添加到容器的View
,蒙版应该与backgroundColor
您的文本容器相同。
使用 react 的flexbox
布局进行一些样式设置,以便能够在每个设备上拥有几乎相同的外观。在此示例中,蒙版采用5/6
屏幕高度,因为我的蒙版flex
编号为 5,我的文本flex
为 1
所以,这就是我最终的结果:
import * as React from 'react';
import { Dimensions, Image, StyleSheet, Text, View } from 'react-native';
import { Path, Svg } from 'react-native-svg';
const mask = {
width: Dimensions.get('window').width,
height: 50,
bgColor: '#ecf0f1',
};
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'flex-end',
},
image: {
position: 'absolute',
},
mask: {
flex: 5,
justifyContent: 'flex-end',
},
textContainer: {
flex: 1,
width: '100%',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: mask.bgColor,
},
text: {
fontSize: 50,
textAlign: 'center',
}
});
const App = () => (
<View style={styles.container}>
<Image style={styles.image} source={require('./assets/image.jpg')} />
<View style={styles.mask}>
<Svg width={mask.width} height={mask.height}>
<Path
fill={mask.bgColor}
d={`M 0 0 L 0 ${mask.height} L ${mask.width} ${mask.height} L ${mask.width} 0 A ${mask.width / 2} ${mask.height / 2} 0 0 1 ${mask.width / 2} ${mask.height / 2} A ${mask.width / 2} ${mask.height / 2} 0 0 1 0 0 z `} />
</Svg>
</View>
<View style={styles.textContainer}>
<Text style={styles.text}>Text</Text>
</View>
</View>
);
export default App;
Run Code Online (Sandbox Code Playgroud)
这是Android
模拟器中的结果
希望这可以帮助!
零食链接:https : //snack.expo.io/BJlZgpuB7(但我的图片无法加载零食:()
归档时间: |
|
查看次数: |
2612 次 |
最近记录: |