【发布时间】:2015-12-31 16:39:09
【问题描述】:
在 React-Native 中,如何为 Text-components 添加字体边框?
我尝试过使用border 和shadow{Color, Radius, Opacity, Offset},但还没有成功。有什么建议吗?
【问题讨论】:
标签: css reactjs react-native
在 React-Native 中,如何为 Text-components 添加字体边框?
我尝试过使用border 和shadow{Color, Radius, Opacity, Offset},但还没有成功。有什么建议吗?
【问题讨论】:
标签: css reactjs react-native
目前不适用于 android。尝试将其包装在这样的视图中:
<View
style={{
borderWidth: 1,
borderColor: "thistle",
borderRadius: 50,
}}>
</View>
【讨论】:
您可以将模拟器边框作为两个属性:
textShadowColor color
textShadowOffset {width: number, height: number}
例如:
textshadow:{
fontSize:100,
color:'#FFFFFF',
fontFamily:'Times New Roman',
paddingLeft:30,
paddingRight:30,
textShadowColor:'#585858',
textShadowOffset:{width: 5, height: 5},
textShadowRadius:10,
},
【讨论】:
我需要为Text 组件添加一个底部边框,如下所示:
我做了以下事情:
边框是<View/>,在另一个带有flexDirection : 'row'的边框内
这是我的代码:
<View style={styles.titleContainer}>
<Text style={styles.title}>Horaire de prière</Text>
<View style={styles.borderContainer}>
<View style={styles.border} />
</View>
</View>
风格:
titleContainer: {
flex: 0.2,
alignItems:'center',
justifyContent:'center'
},
title: {
fontSize: 18,
marginBottom:2,
},
borderContainer:{
flexDirection:'row',
alignItems:'center',
justifyContent:'center',
},
border:{
flex:0.28,
borderBottomWidth: 1,
borderBottomColor: '#428947',
},
您可以使用 flex 修改边框大小。
【讨论】:
paddingTop: 10,
borderWidth: 1,
borderColor: 'red'
【讨论】:
如果您正在寻找类似于 CSS -webkit-text-stroke 工作原理的东西,何不试试 react-native-svg?
import Svg, { Text } from "react-native-svg";
<Svg height="50%" width="50%" viewBox="0 0 100 100">
<Text
stroke="black"
strokeWidth="1"
fill="white"
color="#ffffff"
fontSize="45"
>
Yay!
</Text>
</Svg>
【讨论】:
OutlinedText 可重用组件!
正如 KChen 所说,您需要同时添加borderColor 和borderWidth。只需为更高版本的 ReactNative 更新此答案(注意 'styles.bigblue' 的用法)。
import React, { Component } from 'react';
import { AppRegistry, StyleSheet, ScrollView, Image, Text } from 'react-native';
export default class HelloWorldWithBorder extends Component {
render() {
return (
<ScrollView>
<Text style={styles.bigblue}>HelloWorld WithBorder</Text>
<Text style={styles.bigblue}>HelloWorld WithBorder</Text>
<Text style={styles.bigblue}>HelloWorld WithBorder</Text>
<Text style={styles.bigblue}>HelloWorld WithBorder</Text>
<Text style={styles.bigblue}>HelloWorld WithBorder</Text>
<Text style={styles.bigblue}>HelloWorld WithBorder</Text>
<Text style={styles.bigblue}>HelloWorld WithBorder</Text>
<Text style={styles.bigblue}>HelloWorld WithBorder</Text>
<Text style={styles.bigblue}>HelloWorld WithBorder</Text>
</ScrollView>
);
}
}
const styles = StyleSheet.create({
bigblue: {
color: 'blue',
fontWeight: 'bold',
fontSize: 20,
borderColor: 'black',
borderWidth: 1
}
});
这是使用 Styles 和 ScrollView 的教程的组合
【讨论】:
你需要设置borderColor和borderWidth。
【讨论】:
你至少需要设置borderWidth,它必须设置为一个整数。默认边框颜色为黑色,可以通过borderColor改变颜色
【讨论】:
官方文档为您提供了这些信息。你可以在这个网站上找到它:Text Component。它显示了您可以使用哪些道具来更改组件的行为和样式。如您所见,有一些特定的文本样式,还有您可以在View Component 上应用的样式。如果您点击该链接,它会向您显示边框样式。所以,你正在寻找的可能是:
borderColor string
borderTopColor string
borderRightColor string
borderBottomColor string
borderLeftColor string
borderRadius number
borderTopLeftRadius number
borderTopRightRadius number
borderBottomLeftRadius number
borderBottomRightRadius number
borderStyle enum('solid', 'dotted', 'dashed')
borderWidth number
borderTopWidth number
borderRightWidth number
borderBottomWidth number
borderLeftWidth number
【讨论】: