//
Viewcontroller.m
Uiscollview
//
Created by hehe on 15/9/25.
Copyright (c) 2015 Wang.hehe. All rights reserved.
//
#import "ViewController.h"
#define Width_screen Self.view.bounds.size.width
#define Height_screen Self.view.bounds.size.height
@interface Viewcontroller ()
{
}
@end
@implementation Viewcontroller
-(void) Viewdidload {
[Super Viewdidload];
Self.view.backgroundColor = [Uicolor Graycolor];
[self createuiscroview]; Create a scrolling view
[Self Createlabel]; The first few pages
[Self Creatuipagecontrol]; Create a page Controller
}
#pragma Mark------------------------Createlabel
-(void) Createlabel
{
UILabel *label= [[UILabel alloc]init];
Label.frame = CGRectMake (0, HEIGHT_SCREEN-50, 50, 50);
Label.text = @ "First page";
Label.textcolor = [Uicolor Redcolor];
Label.font = [Uifont systemfontofsize:20];
Label.textalignment = 1;
Label.adjustsfontsizetofitwidth = YES;
[Self.view Addsubview:label];
Label.tag = 11;
}
#pragma Mark------------------------Creatuipagecontrol
-(void) Creatuipagecontrol
{
Uipagecontrol *pc = [[Uipagecontrol alloc] init];
Pc.frame = CGRectMake (height_screen-30, 200, 30);
[Self.view addsubview:pc];
Pc.numberofpages = 4; How many pages
Pc.currentpage = 1; Current page
Pc.pageindicatortintcolor = [Uicolor Greencolor]; The color of the page
Pc.currentpageindicatortintcolor = [uicolor orangecolor];//current page color
Pc.backgroundcolor = [Uicolor whitecolor];//plus background color
[Self.view addsubview:pc];
Pc.tag = 101;
}
#pragma Mark------------------------Scrolling View protocol method
Ways to implement Proxies
-(UIView *) Viewforzoominginscrollview: (Uiscrollview *) ScrollView
{
To achieve the zoom function, two steps are required and the second part
Which view to scale in a scrolling view
return scrollview.subviews[0];
}
-(void) scrollviewdidenddecelerating: (Uiscrollview *) ScrollView
{
UILabel *label1 = (ID) [Self.view viewwithtag:11];
Uipagecontrol *PC1 = (ID) [Self.view viewwithtag:101];
int offset = scrollview.contentoffset.x/self.view.bounds.size.width;
if (offset==5)
{
Scrollview.contentoffset = cgpointmake (self.view.bounds.size.width*1, 0);
}
else if (offset==0)
{
Scrollview.contentoffset = cgpointmake (self.view.bounds.size.width*4, 0);
}
switch (offset)
{
Case 0:
{
Label1.Text = @ "Fourth page";
pc1.currentpage = 3;
Break ;
}
Case 1:
{
pc1.currentpage = 0;
Label1.Text = @ "First page";
Break ;
}
Case 2:
{
pc1.currentpage = 1;
Label1.Text = @ "Second page";
Break ;
}
Case 3:
{
pc1.currentpage = 2;
Label1.Text = @ "the third page";
Break ;
}
Case 4:
{
pc1.currentpage = 3;
Label1.Text = @ "Fourth page";
Break ;
}
Case 5:
{
pc1.currentpage = 0;
Label1.Text = @ "First page";
Break ;
}
Default:
Break ;
}
}
-(void) Createuiscroview
{
//Create a scrolling view object
Uiscrollview *SV = [[Uiscrollview alloc] init];
sv.frame = self.view.bounds;
[Self.view ADDSUBVIEW:SV];
Sv.backgroundcolor = [Uicolor orangecolor];
Sv.contentoffset = Cgpointmake (self.view.bounds.size.width,0); Offset is a point
//Set picture per page, size
for (int i=0;i<6;i++)
{
Uiimageview *iv = [[Uiimageview alloc] Initwithframe:cgrectmake (self.view.bounds.size.width*i, 0, Self.view.bo Unds.size.width, Self.view.bounds.size.height)];
[SV Addsubview:iv];
if (i==0)
{
iv.image = [UIImage imagenamed:@ "3"];
}
else if (i==5)
{
iv.image = [UIImage imagenamed:@ "0"];
}
Else
{
iv.image = [UIImage imagenamed:[nsstring stringwithformat:@ "%d", i-1]];
}
}
sv.contentsize = Cgsizemake (self.view.bounds.size.width*6, self.view.bounds.size.height);
//uiimageview *iv = [[Uiimageview alloc] initwithimage:[uiimage imagenamed:@ "4.jpg"]];//This method adds the original size
sv.bounces = NO; Control whether bounce, default is rebound
Sv.indicatorstyle = uiscrollviewindicatorstylewhite;//Sets the style of the scroll bar
sv.scrollindicatorinsets = uiedgeinsetsmake (0, 0, 0, 30);//Set the position of the scroll bar
sv.showsverticalscrollindicator = no;//set hidden scroll bar
sv.showshorizontalscrollindicator = NO;
//sv.scrollenabled = no;//Set whether scrolling is not allowed to scroll
sv.pagingenabled = YES;//Scroll by page, last must go to a page//set scroll by page
sv.scrollstotop = NO; The default is the yes//setting can go back to the top when the bottom
sv.delegate = self;//Agent <UIScrollViewDelegate>
//Set pinch first step
Sv.minimumzoomscale = 0.5;//Minimum scale, default value is 1
Sv.maximumzoomscale = 5;
//Set deceleration rate: 1 The next, the larger the value, the slower it gets.
sv.decelerationrate = 0;
}
@end
Scrolling view and page control Uiscollview,uipagecontroldemo