如何在iCarousel中使用UIPageControl? [英] How to use UIPageControl with iCarousel?

查看:214
本文介绍了如何在iCarousel中使用UIPageControl?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在icarousel中有一些图像。 (约20张图片)

I have some images within icarousel. (about 20 images)

我想要一页中的5张图片。

I wanna 5 images in a page.

图像像素没有问题或者图像位置。

There is no problem about image pixel or image location.

如何在不使用ScrollView的情况下使用uipagecontrol?

How to use uipagecontrol WITHOUT ScrollView?

ex)能够使用一些委托方法。 。等等。

ex) able to use some delegate methods.. and so on.

carousel.type = iCarouselTypeLinear;
    carousel  = [[iCarousel alloc] initWithFrame:CGRectMake(0, 504, 1024, 164)];
    carousel.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"10004.png"]];
    carousel.delegate = self;
    carousel.dataSource = self;
    [self.view addSubview:carousel];
    [carousel reloadData];
    [carousel release];

    UIView *bandImageView = [[UIView alloc] initWithFrame:CGRectMake(0, 668, 1024, 20)];
    bandImageView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"10001.png"]];
    [self.view addSubview:bandImageView]; // page dots in

    UIPageControl *pageControl = [[UIPageControl alloc] init];
    pageControl.frame = CGRectMake(434, 0, 150, 20); 
    pageControl.numberOfPages = 6; 
    pageControl.currentPage = 0; 
    [bandImageView addSubview:pageControl];
    [pageControl release];


推荐答案

在iCarousel中 carouselCurrentItemIndexUpdated: 委托方法,设置

In the iCarousel carouselCurrentItemIndexUpdated: delegate method, set

pageControl.currentPage = carousel.currentItemIndex / 5

然后将pageControl操作绑定到类似下面的方法:

Then bind your pageControl action to a method like the one below:

- (IBAction)updatePage:(UIPageControl *)pageControl
{
    [carousel scrollToItemAtIndex:pageControl.currentPage * 5 aimated:YES];
}

如果你没有使用nib文件,你可以使用绑定动作

If you're not using a nib file, you can bind the action using

[pageControl addTarget:self action:@selector(updatePage:) forControlEvents:UIControlEventValueChanged];

设置 pageControl.defersCurrentPageDisplay = YES; 以避免闪烁。

这篇关于如何在iCarousel中使用UIPageControl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆