酒吧button项目未正确alignment
我的导航栏有问题,UIBarButtonItem不正确的垂直alignment。 我不知道为什么,因为我使用简单的UIBarButtonItem而不是自定义视图。 看到我的代码下面,感谢您的帮助!
UIBarButtonItem *newGameItem = [[UIBarButtonItem alloc] initWithTitle:@"New Game" style:UIBarButtonItemStyleDone target:self action:@selector(newGame)]; self.navigationItem.rightBarButtonItem = newGameItem;
其实有几个方法来alignment栏button。 尝试调整button标题的位置:
[self.navigationItem.rightBarButtonItem setTitlePositionAdjustment:UIOffsetMake(-10, -10) forBarMetrics:UIBarMetricsDefault];
-10 -10 – 只是例如
要么
你可以用自定义的UIButton
来初始化你的newGameItem
。 自定义button是重写此方法的UIButton的子类
- (UIEdgeInsets)alignmentRectInsets { return UIEdgeInsetsMake(0, -10, 0, 15.0f); // here you can play with values to align your button properly }
然后初始化你的newGameItem
CustomBarButton *button = [CustomBarButton buttonWithType:UIButtonTypeCustom]; [button setTitle:@"New game" forState:UIControlStateNormal]; button.frame = CGRectMake (0, 0, 60, 40); [button addTarget:self action:@selector(newGame) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *newGameItem = [[UIBarButtonItem alloc] initWithCustomView:button]; self.navigationItem.rightBarButtonItem = newGameItem;
我有一个左边的button相同的问题,我可以修复它在Xcode 6.3.1:selectbutton(酒吧button项目)右栏选项卡“标尺”插入图像顶值:-54而不是0.注意那个:我的设备是带有iOS 7的iPhone4,这个button在Xcode中是完全适当的,并且放在设备上,现在放在设备上,放在Xcode里面
我有类似的问题:我们通过UIAppearance
使用自定义字体导航标题和栏button项目,在某些情况下,正确的项目是垂直错位。
我可以通过使用[self.navigationItem setRightBarButtonItem:rightItem animated:YES]
而不是属性设置器来轻松修复错位。
不幸的是,对于UIBarButtonItem
垂直间距,你可以做的UIBarButtonItem
。 我相信你将不得不增加UINavigationBar
的标题的字体大小(你也可以用UIAppearance
来做到这UIAppearance
),或者减less你的UIBarButtonItem
的字体大小。