#import <UIKit/UIKit.h>
#define WIDTH Self.view.frame.size.width
#define HEIGHT Self.view.frame.size.height
@interface viewcontroller:uiviewcontroller<uiscrollviewdelegate, Uipickerviewdelegate, UIPickerViewDataSource >
/**
* Scrolling View
*/
@property (nonatomic, strong) Uiscrollview *scroll;
/**
* Pagination Control
*/
@property (nonatomic, strong) Uipagecontrol *page;
/**
* scroll bar
*/
@property (nonatomic, strong) Uipickerview *pick;
Data source
@property (nonatomic, strong) Nsarray *arr_data;
@end
#import "ViewController.h"
@interface Viewcontroller ()
@end
@implementation Viewcontroller
-(void) viewdidload
{
[Super Viewdidload];
Self.scroll = [[Uiscrollview alloc] initWithFrame:self.view.frame];
Self.scroll.backgroundColor = [Uicolor Graycolor];
Self.scroll.contentSize = Cgsizemake (width*3, HEIGHT);
Page out
self.scroll.pagingEnabled = YES;
Hide scroll bar
Self.scroll.showsHorizontalScrollIndicator = NO;
Uiimageview *IMV1 = [[Uiimageview alloc] initWithFrame:self.view.frame];
Imv1.backgroundcolor = [Uicolor Purplecolor];
Uiimageview *imv2 = [[Uiimageview alloc] initwithframe:cgrectmake (width, 0, width, HEIGHT)];
Imv2.backgroundcolor = [Uicolor Bluecolor];
Uiimageview *imv3 = [[Uiimageview alloc] Initwithframe:cgrectmake (width*2, 0, WIDTH, HEIGHT)];
Imv3.backgroundcolor = [Uicolor Redcolor];
[Self.scroll ADDSUBVIEW:IMV1];
[Self.scroll addsubview:imv2];
[Self.scroll Addsubview:imv3];
[Self.view AddSubview:self.scroll];
Pagination identification
Self.page = [[Uipagecontrol alloc] Initwithframe:cgrectmake ((WIDTH-120)/2, HEIGHT-100, 120, 30)];
Self.page.numberOfPages = 3;
Self.page.backgroundColor = [Uicolor Clearcolor];
[Self.view AddSubview:self.page];
Agent
Self.scroll.delegate = self;
scroll bar
Self.arr_data = @[@ "year", @ "month", @ "Day", @ "time", @ "Min", @ "seconds"];
Self.pick = [[Uipickerview alloc] Initwithframe:cgrectmake ((WIDTH-200)/2, HEIGHT-300, 200, 100)];
Two agents (proxies and data sources)
Self.pick.delegate = self;
Self.pick.dataSource = self;
[Self.view AddSubview:self.pick];
}
Page out
-(void) Scrollviewdidscroll: (Uiscrollview *) ScrollView
{
Self.page.currentPage = (int) scrollview.contentoffset.x/width;
}
Agent
#pragma mark-delegate
-(Nsinteger) Numberofcomponentsinpickerview: (Uipickerview *) Pickerview
{
return 1;
}
#pragma mark-sourcedata
Data source
-(Nsinteger) Pickerview: (Uipickerview *) Pickerview numberofrowsincomponent: (Nsinteger) component
{
return self.arr_data.count;
}
#pragma mark-title
-(Nullable NSString *) Pickerview: (Uipickerview *) Pickerview Titleforrow: (nsinteger) Row forcomponent: (Nsinteger) Component
{
return Self.arr_data[row];
}
#pragma mark-selecter
-(void) Pickerview: (Uipickerview *) Pickerview Didselectrow: (nsinteger) Row incomponent: (Nsinteger) component
{
Row: Subscript
NSLog (@ "%@", Self.arr_data[row]);
}
#pragma mark-rowheight
-(CGFloat) Pickerview: (Uipickerview *) Pickerview rowheightforcomponent: (Nsinteger) component
{
return 50;
}
UIScroll and Uipickview