相信大家都知道新闻类App的首页都会有一些图片在循环播放,今天我来为大家实现这个效果,带UIPageControl的效果。原理就是和相册差不多,再加上一个时间控制器来控制scrollview的偏移量改。
首先设置属相
// 循环播放的scrollView
@property (nonatomic, retain) UIScrollView *topScrollView;
// 小白点
@property (nonatomic, retain) UIPageControl *topPageControl;
// 图片
@property (nonatomic, retain) UIImageView *myImgView;
// 小白点背景
@property (nonatomic, retain) UIView *topView;
// 用来显示文字
@property (nonatomic, retain) UILabel *topLabel;
- (void)installTopScrollView
{
self.topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height * 0.26)];
[self.myTableView.tableHeaderView addSubview:self.topView];
self.topView.backgroundColor = [UIColor clearColor];
self.topScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height * 0.26)];
self.topScrollView.backgroundColor = [UIColor clearColor];
[self.topView addSubview:self.topScrollView];
//8张图片设置topScroll滚动范围为数组+2张图片的大小
self.topScrollView.contentSize = CGSizeMake(self.view.bounds.size.width * (self.bannersArr.count + 2), 0);
//按页滑动