我正在使用UINavigationBar的rightBarButtonItems
属性在导航栏的右侧添加两个按钮。是否可以使这两个按钮之间的间距更宽?
感谢
答案 0 :(得分:6)
您可以在两个按钮之间添加UIBarButtonSystemItemFlexibleSpace
项。
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
答案 1 :(得分:1)
我无法在我的情况下获得灵活的空间,但这里是我以前能够定位rightBarButtonItem的代码:注意,我在UIView周围放置一个边框,这样你就可以看到它的外观在那里有图像。
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;