好多APP都有首次启动显示内容介绍的滑动页面,或者进入APP后界面上部显示的广告栏,那么这些控件的代码编写是不是很繁琐,不怕!今天给大家介绍我写的一套框架,可以直接拿来用,分分钟实现一个无限滚动的广告栏,如下图
•新创建一个UIView类
.h文件
#import <UIKit/UIKit.h>
@interface GDGInfiniteScrollView : UIView
@property(strong,nonatomic) NSArray * images;
@property(weak,nonatomic,readonly)UIPageControl * pageControl;
@property(assign,nonatomic,getter=isScrollDirectionPortrait)BOOL scrollDirectionPortrait;//滚动方向的图片
@end
.m文件
#import "GDGInfiniteScrollView.h"
static int const ImageViewCount = 3;
@interface GDGInfiniteScrollView()<UIScrollViewDelegate>
@property(weak,nonatomic)UIScrollView * scrollView;
@property(weak,nonatomic)NSTimer * timer;
@end
@implementation GDGInfiniteScrollView
-(instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
//滚动视图
UIScrollView * scrollView = [[UIScrollView alloc]init];
scrollView.showsVerticalScrollIndicator = NO;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.pagingEnabled = YES;
scrollView.bounces = NO;
scrollView.delegate = self;
[self addSubview:scrollView];
self.scrollView = scrollView;
//图片控件
for (int i = 0; i <ImageViewCount; i++) {
UIImageV