[英]How to use svg image as background image in react-native?
I use svg in my react-native app next way:接下来我在我的 react-native 应用程序中使用 svg :
import TestLogo from "../../assets/TestLogo.svg";
<TestLogo />
I use background image in next way:我在下一个方式使用背景图像:
import background from '../../assets/modules/auth/signUpPattern.png'
<ImageBackground source={background} style={{width: '100%', height: '100%', alignItems: 'center'}}>
If I use the next syntax:如果我使用下一个语法:
import Background from '../../assets/modules/auth/signUpPattern.svg'
<ImageBackground source={<Background />} style={{width: '100%', height: '100%', alignItems: 'center'}}>
I got empty space, not svg image background, how to fix it?我有空白空间,不是 svg 图像背景,如何解决?
import TestLogo from "../../assets/TestLogo.svg";
<TestLogo />
You can use this for adding background Image for the screen.您可以使用它为屏幕添加背景图像。 Just need to add the style to the TestLogo component.
只需要将样式添加到 TestLogo 组件中即可。
Example:
例子:
<TestLogo
style={{
position: 'absolute',
top: 0,
left: 0,
right: 16,
bottom: 0,
}}
/>
react-native doesn't support .svg formats. react-native 不支持 .svg 格式。 u can use library like react-native-svg or any other.
你可以使用像react-native-svg或任何其他库。
Put it inside the container, style the parent, and that should do the work.将其放入容器中,为父级设置样式,这样就可以了。
import { View, StyleSheet } from "react-native";
import SVGShape from "../assets/icons/path";
export default ShapeSVG = () => {
return (
<View style={{
position: "absolute",
width: "100%",
height: "32%",
bottom: 0,
zIndex: -1, // image is always behind the content
}}>
<SVGShape width={50} height={50} />
</View>
);
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.