现在的位置: 主页 > 商讯 > 文章列表

iOS UI06_UIPageControl

作者:昆明飞华工贸有限公司 来源:www.kmfhgm.com    未知发布时间:2017-09-06 10:13:43
iOS UI06_UIPageControl



//
// MainViewController.m
// UI06_UIPageControl
//
// Created by dllo on 15/8/5.
// Copyright (c) 2015年 zhozhicheng. All rights reserved.
//

#import MainViewController.h
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
@interface MainViewController ()
@property(nonatomic,retain)UIScrollView *scrollView;
@property(nonatomic,retain)UIImageView *imageView;
@end

@implementation MainViewController
-(void)dealloc
{
[_scrollView release];
[_imageView release];
[super dealloc];
}

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
self.scrollView.backgroundColor=[UIColor yellowColor];
[self.view addSubview:self.scrollView];
[self.scrollView release];
self.scrollView.contentSize=CGSizeMake(13 * WIDTH, HEIGHT-100);
self.scrollView.pagingEnabled=YES;
for (NSInteger i=0; i<13; i++) {
NSString *picName=[NSString stringWithFormat:@cymbal_%02ld.jpg,i];
self.imageView =[[UIImageView alloc] initWithImage:[UIImage imageNamed:picName]];
self.imageView.frame=CGRectMake(i * WIDTH, 0, WIDTH, HEIGHT-100);
[self.scrollView addSubview:self.imageView];
[self.imageView release];
}
self.scrollView.contentOffset=CGPointMake(0, 0);
self.scrollView.bounces=NO;
self.scrollView.showsHorizontalScrollIndicator=NO;
self.scrollView.showsVerticalScrollIndicator=NO;
self.scrollView.delegate=self;
UIPageControl *page =[[UIPageControl alloc] initWithFrame:CGRectMake(100, 580, 200, 40)];
page.backgroundColor=[UIColor redColor];
[self.view addSubview:page];
[page release];
//图片个数和点的个数相同
page.numberOfPages =13;
//点的背景颜色
page.pageIndicatorTintColor=[UIColor blackColor];
//被选中的点的颜色
page.currentPageIndicatorTintColor=[UIColor whiteColor];
//添加点击方法
[page addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventValueChanged];
page.tag=1000;
//scrollView缩放
//缩放的比例
self.scrollView.maximumZoomScale=2;
self.scrollView.minimumZoomScale=0.5;
//原始缩放比例
self.scrollView.zoomScale=1;

}
#pragma mark 缩放协议方法
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return [scrollView.subviews firstObject];
}
-(void)pageAction:(UIPageControl *)page
{
//点的个数从0开始
NSLog(@%ld,page.currentPage);
//触发时,进行图片切换
// self.scrollView.contentOffset=CGPointMake(WIDTH * (page.currentPage), 0);
[self.scrollView setContentOffset:CGPointMake(WIDTH * (page.currentPage), 0) animated:YES];

}

//
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
//滑动图片,让圆点跟着一起动
UIPageControl *page=(UIPageControl *)[self.view viewWithTag:1000];
page.currentPage = self.scrollView.contentOffset.x / WIDTH;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end

企业建站2800元起,携手武汉肥猫科技,做一个有见地的颜值派!更多优惠请戳:黄石网站制作 http://huangshi.666rj.com

上一篇:region 私有构造函数 下一篇:最后一页