React Native-图片轮播

图片轮播在App开发中经常使用,这里图片轮播使用的是第三方组件react-native-swiper,
我们启动npm命令行,在项目的根目录使用如下命令安装模块。

$ npm install react-native-swiper --save
$ npm i react-timer-mixin --save

安装好之后 开始写代码,

1,引入第三方组件

var Swiper = require('react-native-swiper');

这样我们在项目中就可以直接使用Swiper组件了。

2,准备好轮播图片的资源,

var images=[
    'http://ac-c6scxa78.clouddn.com/f6b64dc4bf7bee56.jpg',
    'http://ac-c6scxa78.clouddn.com/91ead58b0bb213b6.jpg',
    'http://ac-c6scxa78.clouddn.com/d67316858f6c71f3.jpg',
    'http://ac-c6scxa78.clouddn.com/c81c5b7be1838a1e.jpg',
    'http://ac-c6scxa78.clouddn.com/54fe022399902788.jpg',
];

3

render() {
        return (
            <Swiper height={200}
                >
                {this.renderImg()}
            </Swiper>

        );
    }
    renderImg(){
        var imageViews=[];
        for(var i=0;i<images.length;i++){
            imageViews.push(
                <Image
                    key={i}
                    style={{flex:1}}
                    source={{uri:images[i]}}
                    />
            );
        }
        return imageViews;
    }

效果如下:
这里写图片描述
但是我们发现原点的位置不是我们想要的,那么如何改变原点的位置 以及颜色呢?

 <Swiper height={200}
     paginationStyle={{bottom:10}}
     autoplay={true}
     dot={<View style={{width:8,height:8,backgroundColor:'white',borderRadius:4,marginLeft:3,marginRight:3}}></View>}
     activeDot={<View style={{width:8,height:8,backgroundColor:'orange',borderRadius:4,marginLeft:3,marginRight:3}}></View>}
                >
      {this.renderImg()}
 </Swiper>

paginationStyle设置点的样式,
dot和activeDot设置选中和未选中的样式

这样我们就可以将轮播点的位置设置成我们想要的效果了,
IOS
这里写图片描述
Android
这里写图片描述
还有很多比较好的样式 请参考https://github.com/leecade/react-native-swiper

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值