gpt4 book ai didi

ios - 如何在 React Native 中实现单选按钮

转载 作者:IT王子 更新时间:2023-10-29 08:13:03 31 4
gpt4 key购买 nike

我正在将 React 代码转换为 React Native。所以我需要实现单选按钮。

最佳答案

您可以使用准系统 RN 非常轻松地模仿单选按钮。这是我使用的一个简单实现。根据需要调整大小、颜色等。它看起来像这样(具有不同的色调和一些文本)。在顶部添加 TouchableOpacity 将其变成一个执行某些操作的按钮。

enter image description here

function RadioButton(props) {
return (
<View style={[{
height: 24,
width: 24,
borderRadius: 12,
borderWidth: 2,
borderColor: '#000',
alignItems: 'center',
justifyContent: 'center',
}, props.style]}>
{
props.selected ?
<View style={{
height: 12,
width: 12,
borderRadius: 6,
backgroundColor: '#000',
}}/>
: null
}
</View>
);
}

关于ios - 如何在 React Native 中实现单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31889921/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com