chỉ cần thêm UIBarButtonItem
với FlexibleSpace
cho cả hai bên của hai nút này như dưới đây ..
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
Xem tất cả các mã với hai nút ..
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *locateMe = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemStylePlain target:self action:@selector(locateMe:)];
UIBarButtonItem *request = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemStylePlain target:self action:@selector(request:)];
UIBarButtonItem *menu = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemStylePlain target:self action:@selector(menu:)];
NSArray *toolbarItems = [NSArray arrayWithObjects:locateMe,flexibleSpace,request , flexibleSpace, menu];
[toolBar setItems:toolbarItems animated:NO];
Từ XIB
bạn cũng có thể thiết lập này UIBarButtonSystemItemFlexibleSpace
như trong hình dưới ..

UPDATE: bạn muốn Thêm vào đó nút yêu cầu với hình ảnh đó trên UIToolBar sau đó chỉ cần mang lại cho rằng UIImageView
và nút sau khi thêm UIToolBar
trên UIView
như dưới đây ..
[self.view bringSubviewToFront:imgView];
[self.view bringSubviewToFront:btnRequest];
Nguồn
2013-07-31 11:41:32
mã xin vui lòng .... – IronManGill
ở đây bạn muốn hiển thị hai nút này ở giữa và cho rằng chỉ cần thêm 'UIBarButtonItem' với loại' UIBarButtonSystemItemFlexibleSpace' để điều chỉnh cả hai mặt bằng các nút và đặt các nút này vào giữa để xem câu trả lời của tôi .. :) –