Ios-uipickerview Basic Use

Source: Internet
Author: User

#import "ViewController.h"@interfaceViewcontroller () <UIPickerViewDataSource,UIPickerViewDelegate>{Nsarray*Pickerarray;} @property (Weak, nonatomic) Iboutlet Uipickerview*Mypickerview;@end@implementationViewcontroller- (void) viewdidload{[Super Viewdidload]; _mypickerview.datasource=Self ; _mypickerview.Delegate=Self ; _mypickerview.showsselectionindicator=YES; Pickerarray=[nsarray arraywithobjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"Ten", nil]; }- (void) didreceivememorywarning{[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}-(Nsinteger) Numberofcomponentsinpickerview: (Uipickerview *) pickerview{return 3;}-(Nsinteger) Pickerview: (Uipickerview *) Pickerview numberofrowsincomponent: (nsinteger) component{returnPickerarray.count;}-(UIView *) Pickerview: (Uipickerview *) Pickerview Viewforrow: (nsinteger) Row forcomponent: (Nsinteger) component Reusingview: (UIView *) view{CGRect rect=cgrectmake (0,0, [self Pickerview:pickerview widthforcomponent:row], [self pickerview:pickerview rowheightforcomponent:row]); UIView*testview=[[UIView Alloc]initwithframe:rect];    [TestView Setbackgroundcolor:[uicolor Clearcolor];    [TestView Setopaque:yes]; UILabel*label=[[uilabel Alloc]initwithframe:cgrectmake (8,0, [Self Pickerview:pickerview widthforcomponent:row]-16.0f, [self pickerview:pickerview rowheightforcomponent:row]);    [Label Setbackgroundcolor:[uicolor Clearcolor]; Label.textalignment=Nstextalignmentcenter; Label.text=Pickerarray[row]; Switch(row) { Case 1:         Case 2: {testview.backgroundcolor=component==0?[Uicolor Greencolor]:[uicolor Bluecolor]; }         Case 3: {testview.backgroundcolor=component==0?[Uicolor Browncolor]:[uicolor Redcolor]; }         Break; default: {testview.backgroundcolor=component==0?[Uicolor Graycolor]:[uicolor Orangecolor]; }         Break; } Label.font=[uifont boldsystemfontofsize:14.0f];    [TestView Addsubview:label]; returnTestView;}//dispensable-(NSString *) Pickerview: (Uipickerview *) Pickerview Titleforrow: (nsinteger) Row forcomponent: (nsinteger) component{returnPickerarray[row];}-(CGFloat) Pickerview: (Uipickerview *) Pickerview widthforcomponent: (nsinteger) component; {    return  -;}-(CGFloat) Pickerview: (Uipickerview *) Pickerview rowheightforcomponent: (nsinteger) component{return  -;}- (void) Pickerview: (Uipickerview *) Pickerview Didselectrow: (nsinteger) Row incomponent: (Nsinteger) component{NSLog (@"row=%ld", row);}

Ios-uipickerview Basic Use

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.