UIScroll and Uipickview

Source: Internet
Author: User

    • . h

#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

    • . m

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.