可以使用 RN 的 StyleSheet 和 View 组件来实现一竖排圆圈。具体步骤如下:

  1. 创建一个样式表,定义圆圈的样式:
const styles = StyleSheet.create({
  circle: {
    width: 20,
    height: 20,
    borderRadius: 10,
    backgroundColor: 'red',
    marginVertical: 5,
  },
});
  1. 在 View 组件中使用循环语句生成一组圆圈:
<View>
  {[...Array(5)].map((_, i) => (
    <View key={i} style={styles.circle} />
  ))}
</View>

其中,[...Array(5)] 表示生成一个长度为 5 的数组,map 方法遍历这个数组,生成 5 个圆圈。

完整代码如下:

import React from 'react';
import { View, StyleSheet } from 'react-native';

const styles = StyleSheet.create({
  circle: {
    width: 20,
    height: 20,
    borderRadius: 10,
    backgroundColor: 'red',
    marginVertical: 5,
  },
});

export default function App() {
  return (
    <View>
      {[...Array(5)].map((_, i) => (
        <View key={i} style={styles.circle} />
      ))}
    </View>
  );
}

运行效果如下:

vertical-circles


原文地址: https://www.cveoy.top/t/topic/oSJr 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录