iOS_LoadingController

2015-09-28  本文已影响167人  738bc070cd74

App 启动的引导页制作,如下步骤

#import "LoadingViewController.h"

@interface LoadingViewController ()<UIScrollViewDelegate> {

UIScrollView *_scrollView;
UIPageControl *_pageControl;
int _count;
}

@end

@implementation LoadingViewController

- (void) loadView {
UIImageView *imageView = [[UIImageView alloc] init];
imageView.frame = [UIScreen mainScreen].bounds;
imageView.image = [UIImage imageNamed:@"loading_background.png"];
//imageview 默认不能交互
imageView.userInteractionEnabled = YES;

self.view = imageView;
}

- (void)viewDidLoad {
[super viewDidLoad];
CGSize viewSize = self.view.frame.size;
_count = 4;
_scrollView = [[UIScrollView alloc] init];
_scrollView.frame = self.view.bounds;
_scrollView.showsHorizontalScrollIndicator = NO;
_scrollView.pagingEnabled = YES;
_scrollView.contentSize = CGSizeMake(_count * self.view.bounds.size.width, 0);
_scrollView.delegate = self;
[self.view addSubview:_scrollView];

for (int i = 0; i<_count; i++) {
    [self addImageViewAtIndex:i];
}

_pageControl = [[UIPageControl alloc] init];
_pageControl.center = CGPointMake(viewSize.width * 0.5, viewSize.height * 0.9);
_pageControl.bounds = CGRectMake(0, 0, 100, 0);
_pageControl.numberOfPages = _count;
_pageControl.pageIndicatorTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"loading_pagecontrol_point.png"]];
_pageControl.currentPageIndicatorTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"loading_pagecontrol_checked_point.png"]];
_pageControl.userInteractionEnabled = NO;
[self.view addSubview:_pageControl];
}

- (void) addImageViewAtIndex:(int) index
{
CGSize viewSize = self.view.frame.size;
UIImageView *imageView = [[UIImageView alloc] init];
imageView.frame = CGRectMake(index * viewSize.width, 0, viewSize.width, viewSize.height);
NSString *name = [NSString stringWithFormat:@"loading_%d.png", index+1];
imageView.image = [UIImage imageNamed:name];
[_scrollView addSubview:imageView];

}

- (void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
_pageControl.currentPage = scrollView.contentOffset.x / scrollView.frame.size.width;
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];

}

@end
上一篇下一篇

猜你喜欢

热点阅读