iOS基础·OC高级篇

iOS 轮播滚动视图简洁版(支持GIF)

2020-07-21  本文已影响0人  超级卡布达

先来看看效果吧。使用简单,可自定义位置大小。


shuffling1.gif shuffling2.gif shuffling3.gif shuffling4.gif

此轮播是基于UIScrollView实现的,写得比较简洁,具体代码逻辑可参考代码。上Demo

简单实现思路

1.使用到了模型数组,从而提高了代码的可扩展性。

2.UIScrollView +UIPageControl +UIImageView+UILabel(可添加多个)

  1. UIPageControl、UILabel位置可任意调整提供了pageFrame、titleFrame调整位置

  2. 可设置自动滚动和不滚动(removeTime)

5.简单的网络图片下载类封装管理工具。

6.图片支持gif格式。

7.支持上,左,下,右滚动方向。

使用功能点

1.滚动功能

@property(nonatomic,strong) NSMutableArray  * urlImageArray;//图片地址,可以网络图片也可本地图片
@property(nonatomic,assign)CGFloat timeInterval;//定时滚动时间间隔,默认3秒,开启轮播
@property(nonatomic,assign)UIViewContentMode contentMode;//图片显示模式
@property(nonatomic,assign)NSInteger selIndex;//设置当前选中页码
@property(nonatomic,assign)JHShufflingScrollDirType scrollDirType;//滚动的方向
- (void)removeTime;//如不使用定时器可移除即不使用

2.page功能

@property(nonatomic,assign)BOOL pageHidden;//page是否显示,yes隐藏,No显示
@property(nonatomic,assign)CGRect pageFrame;//page位置
@property(nonatomic,strong)UIColor *pageColor;//默认圆点颜色
@property(nonatomic,strong)UIColor *currentPageColor;//选中圆点颜色
/// 设置page图片
/// @param pageImage 默认图
/// @param currentPageImage 选中图
- (void)setingPageImage:(NSString *)pageImage andCurrentPageImage:(NSString *)currentPageImage;

3.标题功能

//标题1,在设置图片数组前设置,如不设置即不会显示
@property(nonatomic,assign)CGRect title1Frame;//标题1位置
//标题2,在设置图片数组前设置,如不设置即不会显示
@property(nonatomic,assign)CGRect title2Frame;//标题2位置

4.代理功能

//滚动到第几页
- (void)ScrollThePageNumber:(NSInteger)num;
//点击第几页
- (void)ScrollThePageClickNumber:(NSInteger)num;
使用规则
//图片模型数组
    NSMutableArray *imageUrls = [NSMutableArray array];
    JHShufflingModel *model1 = [[JHShufflingModel alloc]init];
    model1.title1 = @"妹子1";
    model1.title1Color = [UIColor redColor];
    model1.title2 = @"妹子1的副标题";
    model1.title2Color = [UIColor greenColor];
    model1.imageUrl = @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1595326302959&di=849856fde4e129cff3cbe2ac71eb4a35&imgtype=0&src=http%3A%2F%2F00.minipic.eastday.com%2F20170420%2F20170420105628_ea6da92abc46098d8e03ad2ee55abeb7_9.jpeg";

    CGFloat bili = 1024.0/1536.0;
    int width = 480*bili;//转整数,宽度不能有小数点位,
//    添加自动轮播器
    JHShufflingView *shufflingView = [[JHShufflingView alloc]initWithFrame:CGRectMake(15, 120, width, 480)];
    shufflingView.delegate = self;
    [self.view addSubview:shufflingView];
    shufflingView.contentMode = UIViewContentModeScaleToFill;//设置图片显示模式
    shufflingView.title1Frame = CGRectMake(0, 0, shufflingView.frame.size.width, 20);//设置标题1的frame
    shufflingView.title2Frame = CGRectMake(0, 30, shufflingView.frame.size.width, 20);//设置标题2的frame
    shufflingView.pageHidden = YES;//隐藏page
    shufflingView.pageColor = [UIColor redColor];//设置未选中page圆点颜色
    shufflingView.currentPageColor = [UIColor yellowColor];//设置选中page圆点颜色
    [shufflingView setingPageImage:@"shuanglingxing" andCurrentPageImage:@"shuanglingxingSel"];//设置page选中与未选中图片

    shufflingView.timeInterval = 2;//设置定时器时间间隔,不设置默认3秒
    shufflingView.scrollDirType = JHShufflingScrollDir_Top;//设置滚动方向

    shufflingView.urlImageArray = imageUrls;//设置图片数组

备注:

如果有不足或者错误的地方还望各位读者批评指正,可以评论留言,笔者收到后第一时间回复。

QQ/微信:976971956/ljh976971956。

简书号:超级卡布达:[简书]

www.jianghu.com

感谢各位观众老爷的阅读,如果觉得笔者写的还凑合,可以关注或收藏一下,不定期分享一些好玩的实用的demo给大家。

文/超级卡布达(简书作者)

著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。

上一篇 下一篇

猜你喜欢

热点阅读