我正在尝试在导航栏中添加自定义按钮,但导航栏中的位置偏离左侧。这是我正在看的(注意“菜单”按钮太远了):
以下是我将按钮添加到当前viewcontroller的方法。在ViewDidLoad中调用setupMenu。
-(void)setupMenu{
self.navigationItem.leftBarButtonItem = [self leftMenuBarButtonItem];
}
- (UIBarButtonItem *)leftMenuBarButtonItem {
UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"GuidanceNavMenu", nil) style:UIBarButtonItemStylePlain target:self action:@selector(popToOpenMenu)];
NSMutableParagraphStyle *paragraphStyle = NSMutableParagraphStyle.new;
[menuButton setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont openSansFontOfSize:14.0f], NSFontAttributeName,
[UIColor blackColor], NSForegroundColorAttributeName,
nil]
forState:UIControlStateNormal];
return menuButton;
}