通过npm安装:npm install react-native-swiper --save import React, {Component} from 'react' import { StyleSheet, Text, View, Image, Dimensions } from 'react-native' import Swiper from 'react-native-swiper' let {height, width} = Dimensions.get('window'); const styles =StyleSheet.create( { wrapper: { }, //整体样式 image:{ height:height, width:width } }); export default class HomePage extends Component{ render(){ return( <Swiper style={styles.wrapper} showsButtons={true} //为false时不显示控制按钮 paginationStyle={{ //小圆点位置 bottom: 70 }} loop={false} //如果设置为false,那么滑动到最后一张时,再次滑动将不会滑到第一张图片。 autoplay={true} //自动轮播 autoplayTimeout={2} //每隔2秒切换 > <Image style={styles.image} source={require('./Image/1.png')}/> <Image style={styles.image} source={require('./Image/2.png')}/> <Image style={styles.image} source={require('./Image/4.png')}/> <Image style={styles.image} source={require('./Image/3.png')}/> <Image style={styles.image} source={require('./Image/5.png')}/> </Swiper> ) } };
swiper 轮播图
最新推荐文章于 2024-08-21 17:47:57 发布