开发者

how to make UIBarButton Right Justified in IPhone

I have added the Toolbar dynamically and in that i added barbutton dynamically but it appears on left side I want it to appear on the开发者_如何转开发 Right Side. Can AnyOne help me Out with this My code Goes Like this

 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];


I got the Answer by Simply adding the following Line

UIBarButtonItem *BtnSpace = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];

and adding this in array Now the Code Look Like this

self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 20, 320, 480) style: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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜