# Import
@ Interface AppDelegate: UIResponder
{
NSMutableArray * _ mutArrImg;
UIPageControl * _ pageControl;
UIScrollView * _ scrollView;
}
@ Property (strong, nonatomic) UIWindow * window;
@ End
# Import "AppDelegate. h"
@ Implementation AppDelegate
-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions
{
Self. window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen] bounds];
// Override point for customization after application launch.
Self. window. backgroundColor = [UIColor whiteColor];
_ ScrollView = [[UIScrollView alloc] initWithFrame: self. window. bounds];
[Self. window addSubview: _ scrollView];
_ ScrollView. delegate = self;
_ ScrollView. contentSize = CGSizeMake (320*4, self. window. frame. size. height );
_ ScrollView. pagingEnabled = YES;
_ MutArrImg = [NSMutableArray arrayWithCapacity: 0];
For (int I = 0; I <4; I ++ ){
NSURL * url = [NSURL URLWithString: @ "http://pica.nipic.com/2007-12-12/20071212235955316_2.jpg"];
Dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ {
NSData * imgData = [NSData dataWithContentsOfURL: url];
UIImage * img = [UIImage imageWithData: imgData];
Dispatch_sync (dispatch_get_main_queue (), ^ {
[_ MutArrImg addObject: img];
UIImageView * imgView = [[UIImageView alloc] initWithFrame: CGRectMake (320 * I, 0,320, self. window. frame. size. height)];
ImgView. image = img;
[_ ScrollView addSubview: imgView];
});
});
}
_ PageControl = [[UIPageControl alloc] initWithFrame: CGRectMake (0,400,320, 30)];
_ PageControl. numberOfPages = 4;
_ PageControl. currentPage = 0;
_ PageControl. pageIndicatorTintColor = [UIColor redColor];
[Self. window addSubview: _ pageControl];
[_ PageControl addTarget: self action: @ selector (actionCotrolPage :) forControlEvents: UIControlEventValueChanged];
[Self. window makeKeyAndVisible];
Return YES;
}
-(IBAction) actionCotrolPage :( id) sender
{
[_ ScrollView setContentOffset: CGPointMake (_ pageControl. currentPage * 320, 0) animated: YES];
}
-(Void) scrollViewDidEndDecelerating :( UIScrollView *) scrollView
{
-PageControl. currentPage = _ scrollView. contentOffset. x/320;
}