2017-01-02 3 views
1

Ich versuche, eine getan Schaltfläche auf der Oberseite des Pickers wie folgt hinzuzufügen. Aber leider konnte ich Button nicht sehen.Hinzufügen einer Werkzeugleiste Fertig Schaltfläche für Auswahl

UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] 
            initWithTitle:@"Done" style:UIBarButtonItemStyleDone 
            target:self action:@selector(done)]; 
UIToolbar *toolBar = [[UIToolbar alloc]initWithFrame: 
          CGRectMake(0, self.view.frame.size.height- 
            picker.frame.size.height-250, self.view.frame.size.width, 50)]; 
[toolBar setBarStyle:UIBarStyleBlackOpaque]; 
NSArray *toolbarItems = [NSArray arrayWithObjects: 
          doneButton, nil]; 
[toolBar setItems:toolbarItems]; 
categoryTF.inputView = picker; 

Antwort

0

Sie haben vergessen, Ihre ToolBar in einer Ansicht hinzuzufügen. Sie können das tun, wie folgt:

[self.view addSubview:toolBar]; 
0

diese Zeile hinzu:

categoryTF.inputAccessoryView = toolBar;

0

Verwenden Symbolleiste und getan Taste für picker

CGRect pickerFrame = CGRectMake(0,kSCREEN_HEIGHT-200,kSCREEN_WIDTH,200); 
UIPickerView * pickerview = [[UIPickerView alloc] initWithFrame:pickerFrame]; 
pickerview.delegate = self; 
pickerview.dataSource = self;  
textField.inputView=pickerview; 

UIToolbar *myToolbar=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, 56)]; 
myToolbar.barStyle=UIBarStyleBlack; 
[myToolbar sizeToFit]; 
myToolbar.backgroundColor=[UIColor whiteColor]; 
NSMutableArray *barItems=[[NSMutableArray alloc]init]; 
UIBarButtonItem *btnItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; 
[barItems addObject:btnItem]; 
UIBarButtonItem *doneBtn=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(pickerDoneClicked)]; 
[barItems addObject:doneBtn]; 
[myToolbar setItems:barItems animated:YES]; 
myToolbar.barStyle = UIBarButtonItemStylePlain; 
myToolbar.barTintColor = [UIColor colorWithRed:0.94f green:0.94f blue:0.96f alpha:1.0f]; 
myToolbar.tintColor=[UIColor blackColor]; 
txtField.inputAccessoryView=myToolbar; 

-(void)pickerDoneClicked 
{ 
[txtField resignFirstResponder]; 
} 
Verwandte Themen