UI06_UIPageControl

#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
@interface RootViewController ()<UIScrollViewDelegate>

@property(nonatomic,retain)UIScrollView *scorllView;
@property(nonatomic,retain)UIPageControl *page;


@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.view.backgroundColor  = [UIColor orangeColor];

    //七张图的相册
    //尺寸是屏幕高的一半,宽是屏幕宽
    self.scorllView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT/2+100)];


    self.scorllView.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:self.scorllView];
    [_scorllView release];

    self.scorllView.contentSize = CGSizeMake(7*WIDTH, 0);
    self.scorllView.pagingEnabled = YES;
    self.scorllView.delegate = self;
    for (NSInteger i = 1; i< 8; i++) {
        NSString *imageName = [NSString stringWithFormat:@"h%ld.jpeg",i];
        UIImage *image = [UIImage imageNamed:imageName];
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((i-1)*WIDTH, 0, WIDTH, HEIGHT/2)];
        imageView.image = image;
        [self.scorllView addSubview:imageView];
        [imageView release];
}




    self.page = [[UIPageControl alloc] initWithFrame:CGRectMake(100, HEIGHT/2+100, 150, 50)];
    self.page.backgroundColor = [UIColor blueColor];
    [self.view addSubview:self.page];
    [_page release];
    self.page.numberOfPages = 7;
    self.page.pageIndicatorTintColor = [UIColor redColor];
    self.page.currentPageIndicatorTintColor = [UIColor greenColor];


    [self.page addTarget:self action:@selector(click:) forControlEvents:UIControlEventValueChanged];


    //设置最大的缩放比例
    self.scorllView.maximumZoomScale = 2;
    //最小的缩放比例
    self.scorllView.minimumZoomScale = 0.5;


}
//控制缩放的方法
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    UIView *view = scrollView.subviews[(NSInteger)scrollView.contentOffset.x/(NSInteger)WIDTH];
    //只要进行缩放,系统就会修改scrollView的contentSize的值,所以当缩小之后,没有办法在进行拖拽
    NSLog(@"%g",scrollView.contentSize.width);
    return view;
}




-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{

    self.page.currentPage = scrollView.contentOffset.x/WIDTH;

}

-(void)click:(UIPageControl *)page{

    NSLog(@"%ld",self.page.currentPage);
    self.scorllView.contentOffset = CGPointMake(WIDTH*page.currentPage, 0);
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc
{
    [_scorllView release];
    [_page release];
    [super dealloc];
}

@end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值