UIPageControl显示在UIImageView之上

时间:2014-04-15 03:17:05

标签: ios pagecontrol

从这个例子中我可以添加pageControl,但pageControl位于屏幕的底部。

如何在底部制作,但在图像的顶部?

我希望图像全屏,图像顶部的页面控件。

示例代码为:

UIPageControl *pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
pageControl.backgroundColor = [UIColor whiteColor];

我尝试使用以下代码重新定位pageControl,但没有成功:

pageControl.frame = CGRectMake(0,500,320,30);

1 个答案:

答案 0 :(得分:0)

尝试根据您的需要调整此类内容:

 @interface ViewController () 
 {
     UIPageControl *pageControl;
 }


- (void)viewDidLoad
{
    [super viewDidLoad];

    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,320,480)];
    imageView.image = [UIImage imageNamed:@"soccer.jpg"];
    [self.view addSubview:imageView];

    pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0,200,320,480)];
    pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
    pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
    pageControl.numberOfPages = 5;
    pageControl.currentPage = 0;
    pageControl.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:pageControl];

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

 }


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

    switch (page.currentPage) {
        case 0:
            pageControl.backgroundColor=[UIColor redColor];
            break;

        case 1:
            pageControl.backgroundColor=[UIColor grayColor];
            break;

        case 2:
            pageControl.backgroundColor=[UIColor orangeColor];
            break;

        case 3:
            pageControl.backgroundColor=[UIColor greenColor];
            break;

        case 4:
            pageControl.backgroundColor=[UIColor blueColor];
            break;

        case 5:
            pageControl.backgroundColor=[UIColor yellowColor];
            break;

        default:
            break;
    }

}