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

标签 ios reactjs react-native

我正在将 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/

相关文章:

ios - 在每行 3 个单元格布局中将 cornerRadius 添加到第一个和第三个 UICollectionViewCell

ios - cellForItemAt 在 Swift collectionView 中仅调用一次

ios - 如何将UIWebView放入框架中

javascript - React 路由器未匹配任何路由

javascript - 使用 Realm 结果 react native ListView

iOS 崩溃堆栈解密

javascript - React.js 切换显示

javascript - React-Meteor "cannot read property X of undefined"来自另一个页面

react-native - 使用 Command-R 在 iOS 模拟器中重新加载应用程序不起作用

reactjs - 无法运行 jetifier React Native