javascript - React Native 在 SVG 图像上放置一个文本
问题描述
我正在使用库:“react-native-svg”:“12.1.0”和“react-native-svg-transformer”:“0.14.3”
import FooIcon from '../assets/images/icons/fooIcon.svg';
<View style={{ flex: 1, paddingTop: 8 }}>
<FooIcon></FooIcon>
<View style={{ position: 'absolute', top: 35, bottom: 0, left: 14, right: 0 }} >
<Text>foo</Text>
</View>
</View>
如何让“foo”文本以 FooIcon 为中心。上面的解决方案没有使文本居中,这很重要,因为“foo”文本长度可以改变,并且在每种情况下都必须居中。
解决方案
这段代码应该为您完成工作
<View
style={{
justifyContent: 'center',
alignItems: 'center'
}}
>
<SVG /> //your svg image component goes here
<Text
style={{
position: 'absolute'
}}
>
Test
</Text>
</View>
推荐阅读
- javascript - 编译 ejs i18next 时出现意外的令牌
- c# - 如何增加 RemoteWebDriver 的 HTTP 请求超时
- python - 如何创建一个仅在满足某些条件时才发生实例化的类?
- javascript - 如何在 Bootstrap 的页面刷新时保持当前 Accordion 处于活动状态
- php - 无法从连接表中检索数据
- java - 值 1 和值 2 的偶数
- c++ - 标准库是否提供类型列表?
- javascript - 反应路由器记忆路由向导
- android - 使用 gradle 为带有风味的库上传存档
- linq - 如何使用 linq 遍历所有图像,但只搜索这些图像中字符串的一部分?