How to implement views to the pagecontrol

社会主义新天地 提交于 2019-12-13 11:35:45

问题


I'm about to create an App.

It should have 3 main pages. So I thought of achieving this with a PageControl.

I created 3 Views and now i am stuck on the implementation of this PageControl.

Has anyone a good tutorial or a example code where i take can look at (it can be german too)?

Thanks, Michael


回答1:


Here's a simple idea of how to use it.

PageController.h:

#import <UIKit/UIKit.h>

@interface PageController : UIViewController {
    NSArray * views;
    UIPageControl *pageControl;
}

@property (nonatomic, retain) IBOutlet UIPageControl * pageControl;

- (IBAction) changePage:(id)sender;
- (void) animateToView:(UIView *)newView;

@end

PageController.m:

#import "PageController.h"

@implementation PageController

- (void)viewDidLoad {
    [super viewDidLoad];
    pageControl.numberOfPages = [views count];
    pageControl.currentPage = 0;

    // Either wire this up in Interface Builder or do it here.
    [pageControl addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventValueChanged];
}

- (IBAction) changePage:(id)sender {
    UIView * newView = [views objectAtIndex:[pageControl currentPage]];
    [self animateToView:newView];
}

- (void) animateToView:(UIView *)newView {
     // You'd have to implement this yourself
}

@end


来源:https://stackoverflow.com/questions/2230665/how-to-implement-views-to-the-pagecontrol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!