2012-02-09 31 views

Trả lời

6

Bạn có thể thêm một mặt hàng UIBarButtonSystemItemFlexibleSpace giữa hai nút.

UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace 
                     target:nil 
                     action:nil]; 
+0

cảm ơn, nó hoạt động. nhưng làm thế nào để tôi xác định chiều rộng? – atnatn

+3

Tôi giả sử tôi nên sử dụng 'UIBarButtonSystemItemFixedSpace': D – atnatn

+0

@atnatn Có thể' item.width' hoạt động, tôi chưa thử nghiệm. – fannheyward

1

tôi đã không thể để có được không gian linh hoạt để làm việc trong hoàn cảnh của tôi, nhưng đây là đoạn code tôi đã sử dụng để có thể xác định vị trí các rightBarButtonItem: Lưu ý, tôi đặt một đường viền xung quanh UIView để bạn có thể xem những gì có vẻ như có hình ảnh trong đó.

UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(89,40,100,30)]; 
containerView.layer.borderColor = [[UIColor redColor] CGColor]; 
containerView.layer.borderWidth = 1.0; 
UIImage *image = [UIImage imageNamed:@"nav-icon.png"]; 
UIButton *navigationButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
[navigationButton setFrame:CGRectMake(67,0,25,25)]; 
[navigationButton setImage:image forState:UIControlStateNormal]; 
[containerView addSubview:navigationButton]; 

UIBarButtonItem *navigationBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:containerView]; 

self.navigationItem.rightBarButtonItem = navigationBarButtonItem; 
Các vấn đề liên quan