UIPageControl显示在UIImageView的顶部



从这个例子中,我可以添加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);

试着根据您的需求调整这样的东西:

 @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;
    }
}

相关内容

  • 没有找到相关文章

最新更新