先来看看效果吧。
此轮播是基于UIScrollView实现的,写得比较简洁,具体代码逻辑可参考代码。上Demo
######简单实现思路
1.使用到了模型数组,从而提高了代码的可扩展性。
2.UIScrollView +UIPageControl +UIImageView+UILabel(可添加多个)
3. UIPageControl、UILabel位置可任意调整提供了pageFrame、titleFrame调整位置
4. 可设置自动滚动和不滚动(removeTime)
5.简单的网络图片下载类封装管理工具。
使用规则
//图片模型数组
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.urlImageArray = imageUrls;//设置图片数组