UIScrollView分页
一、基本分页(一个图片)
只要将UIScrollView的pageEnabled属性设置为YES,UIScrollView会被分割成多个独立页面,
里面的内容就能进行分页展示
一般会配合 UIPageControl 增强分页效果,UIPageControl常用属性如下
一共有多少页
@property(nonatomic) NSInteger numberOfPages;
当前显示的页码
@property(nonatomic) NSInteger currentPage;
只有一页时,是否需要隐藏页码指示器
@property(nonatomic) BOOL hidesForSinglePage;
其他页码指示器的颜色
@property(nonatomic,retain) UIColor *pageIndicatorTintColor;
当前页码指示器的颜色
@property(nonatomic,retain) UIColor *currentPageIndicatorTintColor;
二、基本分页代码实例
//
// ViewController.m
// 03_UIScrollView08_分页
//
// Created by 杞文明 on 15/12/26.
// Copyright © 2015年 杞文明. All rights reserved.
//
#import "ViewController.h"
@interface ViewController (){
UIScrollView* _scrollView;
UIImageView* _imageView;
// 分页控件
UIPageControl *_pager;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self createUIScrollView];
}
/**UIScrollView的创建和设置*/
-(void)createUIScrollView{
//1.创建UIScrollView 并添加到view中
_scrollView = [[UIScrollView alloc]initWithFrame:self.view.bounds];
[self.view addSubview:_scrollView];
//2.创建图片
UIImage * image = [UIImage imageNamed:@"测试"];
//3.创建UIImageView 对象,把图片点击到ImageView中
_imageView = [[UIImageView alloc]initWithImage:image];
//4.把UIImageView 对象添加到UIScrollView中
[_scrollView addSubview:_imageView];
//5.设置UIScrollView的一些属性
//5.1 设置滚动范围
[_scrollView setContentSize:image.size];
// //5.2添加四周的滚动范围
// UIEdgeInsets edgeInsets = UIEdgeInsetsMake(10.0,