IOS custom Date and data source selection control

Source: Internet
Author: User
Demand

App development often has a date selection (such as birthdays, sleep timing, etc.) or provincial urban choice such functions, usually the UI does not use the control in the UI alone, but on the basis of Uipickerview to add a cancellation and Confirm button features to support the common selection of data format
The control integrates YYYY-MM-DD, yyyy-mm, HH MM, provincial and municipal, provincial and municipal cascading, custom data sources (2 columns), custom data sources (3 columns), and many other formats, that is, support Uitextfield and event triggering mechanisms support Xib also support pure code effect diagram

Github:https://github.com/mengday/xxpickerview Integration

First drag the Xxpickerview folder into the project Pure code (select any of the modes)

#import "ViewController.h" #import "XXTextField.h" #define Random (R, G, B, a) [Uicolor colorwithred: (r)/255.0 Green: (g)/2 55.0 Blue: (b)/255.0 Alpha: (a)/255.0] #define Randomcolor random (Arc4random_uniform (256), Arc4random_uniform (256), Arc4random_uniform (256), Arc4random_uniform (256)) @implementation Viewcontroller-(void) viewdidload {[Super Viewdi

    Dload];
    CGFloat x = 170;
    CGFloat width = 178;
    CGFloat height = 30;

    CGFloat margin = 50;
    Mode one Xxtextfield *textfield = [[Xxtextfield alloc] init];
    Textfield.frame = CGRectMake (x, N, width, height);
    Textfield.mode = xxpickerviewmodedate;
    Textfield.backgroundcolor = Randomcolor;

    [Self.view Addsubview:textfield];
    Mode two Xxtextfield *textfield2 = [[Xxtextfield alloc] init];
    Textfield2.frame = CGRectMake (x, Textfield.frame.origin.y + margin, width, height);
    Textfield2.mode = Xxpickerviewmodeyearandmonth;
    Textfield2.backgroundcolor = Randomcolor; [Self.view Addsubview:textFIELD2];
    Mode three Xxtextfield *textfield3 = [[Xxtextfield alloc] init];
    Textfield3.frame = CGRectMake (x, Textfield2.frame.origin.y + margin, width, height);
    Textfield3.mode = Xxpickerviewmodehourandminute;
    Textfield3.backgroundcolor = Randomcolor;

    [Self.view addsubview:textfield3];
    Mode four Xxtextfield *textfield4 = [[Xxtextfield alloc] init];
    Textfield4.frame = CGRectMake (x, Textfield3.frame.origin.y + margin, width, height);
    Textfield4.mode = xxpickerviewmodeprovincecity;
    Textfield4.backgroundcolor = Randomcolor;

    [Self.view Addsubview:textfield4];
    Mode five Xxtextfield *textfield5 = [[Xxtextfield alloc] init];
    Textfield5.frame = CGRectMake (x, Textfield4.frame.origin.y + margin, width, height);
    Textfield5.mode = Xxpickerviewmodeprovincecityareas;
    Textfield5.backgroundcolor = Randomcolor;

    [Self.view ADDSUBVIEW:TEXTFIELD5];
    Mode six Xxtextfield *textfield6 = [[Xxtextfield alloc] init]; Textfield6.frame = CgreCtmake (x, Textfield5.frame.origin.y + margin, width, height);
    Textfield6.mode = Xxpickerviewmodedatasourcefor2column;
    Textfield6.datasource = [Datasourcefor2column mutablecopy];
    Textfield6.backgroundcolor = Randomcolor;

    [Self.view Addsubview:textfield6];
    Mode VII Xxtextfield *TEXTFIELD7 = [[Xxtextfield alloc] init];
    Textfield7.frame = CGRectMake (x, Textfield6.frame.origin.y + margin, width, height);
    Textfield7.mode = Xxpickerviewmodedatasourcefor3column;
    Textfield7.datasource = [Datasourcefor3column mutablecopy];
    Textfield7.backgroundcolor = Randomcolor;
   [Self.view Addsubview:textfield7]; } @end
Xib Way

Binding Custom Classes

Drag the line and set the mode

@interface Viewcontroller ()
@property (weak, nonatomic) Iboutlet Xxtextfield *textfield;
@end

@implementation Viewcontroller

-(void) viewdidload {
    [super viewdidload];
    _textfield.mode = xxpickerviewmodedate;
}

@end
Event Mode
Related Article

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.