tôi đang sử dụng thuộc tính rightBarButtonItems
của UINavigationBar để thêm hai nút ở bên phải thanh điều hướng của tôi. có thể tạo khoảng cách giữa hai nút này rộng hơn không?khoảng cách rightBarButtonMặt hàng trong UINavigationBar
cảm ơn
tôi đang sử dụng thuộc tính rightBarButtonItems
của UINavigationBar để thêm hai nút ở bên phải thanh điều hướng của tôi. có thể tạo khoảng cách giữa hai nút này rộng hơn không?khoảng cách rightBarButtonMặt hàng trong UINavigationBar
cảm ơn
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];
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ảm ơn, nó hoạt động. nhưng làm thế nào để tôi xác định chiều rộng? – atnatn
Tôi giả sử tôi nên sử dụng 'UIBarButtonSystemItemFixedSpace': D – atnatn
@atnatn Có thể' item.width' hoạt động, tôi chưa thử nghiệm. – fannheyward