In fact, Uipickerview and uitableview implementation methods, roughly the same, even the role is the same, just use in a different effect only, then the following records a few methods can achieve Uipickerview effect:
1. Set the Uipickerview column
-(Nsinteger) Numberofcomponentsinpickerview: (Uipickerview *) Pickerview;
2, set the line of Uipickerview
-(Nsinteger) Pickerview: (Uipickerview *) Pickerview numberofrowsincomponent: (nsinteger) component;
3, set the line height of Uipickerview
-(CGFloat) Pickerview: (Uipickerview *) Pickerview rowheightforcomponent: (nsinteger) component;
4, set the text information of Uipickerview
-(NSString *) Pickerview: (Uipickerview *) Pickerview Titleforrow: (nsinteger) Row forcomponent: (Nsinteger) component;
5. Uipickerview Click events
-(void) Pickerview: (Uipickerview *) Pickerview Didselectrow: (nsinteger) Row incomponent: (Nsinteger) component;
with the 5 steps above, you can achieve a scrolling effect. However, here is a problem, is not like UITableView in the cell method to set [morecell. textlabel setfont :[ Uifont systemfontofsize : 15.0f ]]; Style or font size, this involves another implementation in Uipickerview:
-(UIView *) Pickerview: (Uipickerview *) Pickerview Viewforrow: (nsinteger) Row forcomponent: (Nsinteger) component Reusingview: (UIView *) view{ UILabel *laltitle= (UILabel *) view; if (!laltitle) { Laltitle=[[uilabel alloc] init]; laltitle.minimumscalefactor=8;//sets the minimum font, which is the same as minimumfontsize, minimumfontsize cannot be used after iOS 6. laltitle.adjustsfontsizetofitwidth=yes;//Sets whether the font size fits Lalbel width laltitle.textalignment= nstextalignmentcenter;//Text Center display [Laltitle settextcolor:[uicolor blackcolor]; [Laltitle Setfont:[uifont systemfontofsize:17.0f]; } Laltitle.text=[self Pickerview:pickerview Titleforrow:row forcomponent:component]; return laltitle; }
To this, Uipickerview's simple and practical realization!!!!
Easy and Practical IOS Uipickerview