2010-07-12 3 views
1

J'ai ajouté le Toolbar dynamiquement et en cela j'ai ajouté barbutton dynamiquement, mais il apparaît sur le côté gauche, je veux qu'il apparaisse sur le côté droit. Quelqu'un peut-il me aider avec ce Mon code va comme cecicomment faire UIBarButton à droite Justifié dans IPhone

CGRect frame = CGRectMake(0, 205, 320, 40); 
UIToolbar *toolbar = [[UIToolbar alloc]initWithFrame:frame]; 
toolbar.barStyle =UIBarStyleBlackTranslucent; 
toolbar.tintColor = [UIColor darkGrayColor]; 


UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle: @"Done" style:UIBarButtonItemStyleDone target:self action:@selector(foo)]; 
NSArray *array = [[NSArray alloc]initWithObjects:backButton,nil]; 

[toolbar setItems:array]; 

Répondre

2

Je suis la réponse en ajoutant simplement la ligne suivante

UIBarButtonItem * BtnSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: cible UIBarButtonSystemItemFlexibleSpace: auto actions :néant];

et en ajoutant dans le tableau Maintenant, le code Ressemblez cette

self.tableView = [[UITableView alloc] initWithFrame: le style CGRectMake (0, 20, 320, 480): UITableViewStyleGrouped]; CGRect frame = CGRectMake (0, 205, 320, 40); UIToolbar * toolbar = [[UIToolbar alloc] initWithFrame: frame]; toolbar.barStyle = UIBarStyleBlackTranslucent; toolbar.tintColor = [UIColor darkGrayColor];

UIBarButtonItem *BtnSpace = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; 
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle: @"Done" style:UIBarButtonItemStyleDone target:self action:@selector(foo)]; 
NSArray *array = [[NSArray alloc]initWithObjects:BtnSpace,backButton,nil]; 

[toolbar setItems:array]; 
Questions connexes