The effect is as follows:
ViewController.h
1 #import <UIKit/UIKit.h>23@interface Viewcontroller:uiviewcontroller <uipickerviewdatasource, uipickerviewdelegate>4@end
Viewcontroller.m
1 #import "ViewController.h"2 3 @interfaceViewcontroller ()4- (void) Layoutui;5 @end6 7 @implementationViewcontroller8 9- (void) Viewdidload {Ten [Super Viewdidload]; One A [self layoutui]; - } - the- (void) didreceivememorywarning { - [Super didreceivememorywarning]; - //Dispose of any resources the can be recreated. - } + -- (void) Layoutui { +Uipickerview *pikvcustom = [[Uipickerview alloc] Initwithframe:cgrectmake (0,0,0,0)]; APikvcustom.center =Self.view.center; atPikvcustom.datasource =Self ; -Pikvcustom.Delegate=Self ; - [Self.view Addsubview:pikvcustom]; - } - - #pragmaMark-pickerview in-(Nsinteger) Numberofcomponentsinpickerview: (Uipickerview *) Pickerview { - return 2;//returns the number of component columns to } + --(Nsinteger) Pickerview: (Uipickerview *) Pickerview numberofrowsincomponent: (Nsinteger) component { the return Ten;//returns the number of component rows * } $ Panax Notoginseng-(NSString *) Pickerview: (Uipickerview *) Pickerview Titleforrow: (nsinteger) Row forcomponent: (Nsinteger) component { -NSString *strtitle =@""; the if(Component = =0) { +strtitle = [NSString stringWithFormat:@"%2ld", row+1]; A}Else { thestrtitle = [NSString stringWithFormat:@"comparison of long strings, where%ld", row+1]; + } - returnStrtitle;//returns the component row header $ } $ --(CGFloat) Pickerview: (Uipickerview *) Pickerview widthforcomponent: (Nsinteger) component { - returnComponent = =0? +:280;//Return component Width the } - Wuyi-(CGFloat) Pickerview: (Uipickerview *) Pickerview rowheightforcomponent: (Nsinteger) component { the return +;//returns the component row height - } Wu - @end
094 setting selector box row and column dimensions