#import "MJViewController.h"
#define KCOUNT 8//definition macros, frequently used in programs, easy to expand
@interface Mjviewcontroller () <UIScrollViewDelegate>
{
Uipagecontrol *_pagecontrol;
}
@end
@implementation Mjviewcontroller
-(void) viewdidload
{
[Super Viewdidload];
CGFloat w = self.view.frame.size.width;
CGFloat h = self.view.frame.size.height;
for (int i = 0; i< kcount; i++) {
Uiimageview *imageview = [[Uiimageview alloc] init];
1. Set the frame
Imageview.frame = CGRectMake (i * w, 0, W, h);
2. Setting up a picture
NSString *imgname = [NSString stringwithformat:@ "0%d.jpg", i + 1];
Imageview.image = [UIImage imagenamed:imgname];
[_scrollview Addsubview:imageview];
}
Height = = 0 means no vertical scrolling
_scrollview.contentsize = Cgsizemake (kcount * w, 0);
_scrollview.showshorizontalscrollindicator = NO;
_scrollview.pagingenabled = YES;
_scrollview.delegate = self;
Add Pagecontrol
Uipagecontrol *pagecontrol = [[Uipagecontrol alloc] init];
Pagecontrol.center = Cgpointmake (w * 0.5, h-20);
Pagecontrol.bounds = CGRectMake (0, 0, 150, 50);
Pagecontrol.numberofpages = Kcount; show how many dots (how many pages)
Set the dot color of a non-selected page
Pagecontrol.pageindicatortintcolor = [Uicolor Redcolor];
Set the dot color of the selected page
Pagecontrol.currentpageindicatortintcolor = [Uicolor Bluecolor];
Disable the default click function
pagecontrol.enabled = NO;
[Self.view Addsubview:pagecontrol];
_pagecontrol = Pagecontrol;
}
Proxy methods for #pragma mark-uiscrollview
#pragma mark calls when ScrollView is rolling.
-(void) Scrollviewdidscroll: (Uiscrollview *) ScrollView
{
int page = Scrollview.contentoffset.x/scrollview.frame.size.width;
NSLog (@ "%d", page);
Set Page numbers
_pagecontrol.currentpage = page;
}
@end
Uiscrollview Picture page display, here to use the Uipagecontrol