滚动视图

@interface ViewController ()
#define w self.view.frame.size.width// 屏幕宽度
#define h self.view.frame.size.height// 屏幕高度
{
UIScrollView* scroll ;


UIPageControl * page ;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];


NSArray *arr= @[@"1-1",@"2-1",@"3-1",@"4-1"];
// 轮播图
scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, w, h)];


// 滚动的范围
scroll.contentSize=CGSizeMake(4*w,h);


// 分页
scroll.pagingEnabled = YES ;


// 隐藏水平滚动条
scroll.showsHorizontalScrollIndicator = NO ;


// 取消弹簧效果
scroll.bounces=NO;


// 代理
scroll.delegate=self;




for(inti =0; i <4; i++)
{
// 图片框
UIImageView* imgV = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:arr[i]]];


// 位置
imgV.frame=CGRectMake(i *w,0,w,h);


// 用户交互
imgV.userInteractionEnabled = YES ;


if(i ==3)
{
// 跳转主控按钮
UIButton* btn = [[UIButtonalloc]initWithFrame:CGRectMake(170,550,80,40)];


// 文字
[btnsetTitle:@"点击体验"forState:UIControlStateNormal];


// 文字颜色
[btnsetTitleColor:[UIColor greenColor] forState:UIControlStateNormal];


// 边框宽度
btn.layer.borderWidth=2;


// 颜色
btn.layer.borderColor= [UIColorgreenColor].CGColor;


// 圆角
btn.layer.cornerRadius=10;


// 裁剪
btn.layer.masksToBounds=YES;


// 添加事件
[btnaddTarget:self action:@selector(tiao) forControlEvents:UIControlEventTouchUpInside];


// 加入scroll中
[imgVaddSubview:btn];




}
// 加入图片
[scrolladdSubview:imgV];
}
// 加入视图
[self.view addSubview:scroll];




//显示的点
page= [[UIPageControlalloc]initWithFrame:CGRectMake((w-100) /2,650,100,30)];


// 点的个数
page.numberOfPages = 4 ;


// 设置页码的颜色
page.pageIndicatorTintColor = [UIColor greenColor];


// 选中页码的颜色
page.currentPageIndicatorTintColor = [UIColor yellowColor];
;
// 禁用
page.enabled=NO;


// 加入视图
[self.view addSubview:page];


}
-(void)tiao
{
twoViewController * vc =[[twoViewController alloc]init];


UINavigationController * vcNav = [[UINavigationController alloc]initWithRootViewController:vc];


[self presentViewController:vcNav animated:YES completion:nil];
}
// 选中后进入此方法
-(void)scrollViewDidScroll:(UIScrollView*)scrollView
{
// 点 随 选中的页码变化
page.currentPage = scroll.contentOffset.x / w ;
【滚动视图】}

    推荐阅读