导航栏右侧按钮放置不正确
Navigationbar right button is not placed correctly
我用 4 个项目实现了 UITabBarController
。
我从AppDelegate
设置初始的ViewController
。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
HomeTabBarViewController* homeVC = [[HomeTabBarViewController alloc] init];
[self.window setRootViewController:homeVC];
[self.window makeKeyAndVisible];
return YES;
}
这里是HomeTabBarViewController
ViewDidLoad
代码:
UIViewController *view1 = [[UIViewController alloc] init];
[view1.view setBackgroundColor:[UIColor redColor]];
UIViewController *view2 = [[UIViewController alloc] init];
UINavigationController * centerNav=[[UINavigationController alloc]initWithRootViewController:view1];
HomePagingViewController * view3=(HomePagingViewController*)[storyboard instantiateViewControllerWithIdentifier:@"HomePagingViewController"];
UINavigationController * centerNav3=[[UINavigationController alloc]initWithRootViewController:view3];
UIViewController *view4 = [[UIViewController alloc] init];
UINavigationController * centerNav4=[[UINavigationController alloc]initWithRootViewController:view4];
[view2.view setBackgroundColor:[UIColor greenColor]];
[view3.view setBackgroundColor:[UIColor purpleColor]];
[view4.view setBackgroundColor:[UIColor grayColor]];
NSMutableArray *tabViewControllers = [[NSMutableArray alloc] init];
[tabViewControllers addObject:centerNav];
[tabViewControllers addObject:view2];
[tabViewControllers addObject:centerNav3];
[tabViewControllers addObject:centerNav4];
[self setViewControllers:tabViewControllers];
view1.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Home"
image:[UIImage imageNamed:@"home_tab_item.png"] selectedImage:[UIImage imageNamed:@"home_tab_item_active.png"]] ;
view2.tabBarItem =
[[UITabBarItem alloc] initWithTitle:@"Bookmark"
image:[UIImage imageNamed:@"bookmark_tab_item.png"] selectedImage:[UIImage imageNamed:@"bookmark_tab_item_active.png"]];
view3.tabBarItem =
[[UITabBarItem alloc] initWithTitle:@"Paper"
image:[UIImage imageNamed:@"paper_tab_item.png"] selectedImage:[UIImage imageNamed:@"paper_tab_item_active.png"]];
view4.tabBarItem =
[[UITabBarItem alloc] initWithTitle:@"More"
image:[UIImage imageNamed:@"menu_tab_item.png"] selectedImage:[UIImage imageNamed:@"menu_tab_item_active.png"]];
在 HomePagingViewController
ViewDidLoad
中,我按照代码
设置了导航
-(void)navigationSetUp{
self.navigationController.navigationBar.translucent=NO;
UIBarButtonItem * settingBtn=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"settings.png"] style:UIBarButtonItemStylePlain target:self action:@selector(menuHandler:)];
UIBarButtonItem * searchBtn=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"settings.png"] style:UIBarButtonItemStylePlain target:self action:@selector(menuHandler:)];
self.navigationItem.leftBarButtonItem = settingBtn;
self.navigationItem.rightBarButtonItem = searchBtn;
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ie_New_logo.png"]];
}
在此之后,当我更改 HomePagingViewController
的选项卡时,导航右侧按钮放置不正确,右侧没有边距。
参考图片:
请帮忙。
我解决了这个问题,代码没有问题。实际上对于 Epaper 我们使用第三方 SDK 所以这个问题 occur.I 删除了 SDK & 代码现在工作正常。
你应该想想UIBarButtonSystemItemFixedSpace
效果。
- 例如:
UIBarButtonItem * space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
--
- 为什么要用系统导航栏?自定义导航栏就好了!赞:https://github.com/chenliangloveyou/EasyNavigation
我用 4 个项目实现了 UITabBarController
。
我从AppDelegate
设置初始的ViewController
。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
HomeTabBarViewController* homeVC = [[HomeTabBarViewController alloc] init];
[self.window setRootViewController:homeVC];
[self.window makeKeyAndVisible];
return YES;
}
这里是HomeTabBarViewController
ViewDidLoad
代码:
UIViewController *view1 = [[UIViewController alloc] init];
[view1.view setBackgroundColor:[UIColor redColor]];
UIViewController *view2 = [[UIViewController alloc] init];
UINavigationController * centerNav=[[UINavigationController alloc]initWithRootViewController:view1];
HomePagingViewController * view3=(HomePagingViewController*)[storyboard instantiateViewControllerWithIdentifier:@"HomePagingViewController"];
UINavigationController * centerNav3=[[UINavigationController alloc]initWithRootViewController:view3];
UIViewController *view4 = [[UIViewController alloc] init];
UINavigationController * centerNav4=[[UINavigationController alloc]initWithRootViewController:view4];
[view2.view setBackgroundColor:[UIColor greenColor]];
[view3.view setBackgroundColor:[UIColor purpleColor]];
[view4.view setBackgroundColor:[UIColor grayColor]];
NSMutableArray *tabViewControllers = [[NSMutableArray alloc] init];
[tabViewControllers addObject:centerNav];
[tabViewControllers addObject:view2];
[tabViewControllers addObject:centerNav3];
[tabViewControllers addObject:centerNav4];
[self setViewControllers:tabViewControllers];
view1.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Home"
image:[UIImage imageNamed:@"home_tab_item.png"] selectedImage:[UIImage imageNamed:@"home_tab_item_active.png"]] ;
view2.tabBarItem =
[[UITabBarItem alloc] initWithTitle:@"Bookmark"
image:[UIImage imageNamed:@"bookmark_tab_item.png"] selectedImage:[UIImage imageNamed:@"bookmark_tab_item_active.png"]];
view3.tabBarItem =
[[UITabBarItem alloc] initWithTitle:@"Paper"
image:[UIImage imageNamed:@"paper_tab_item.png"] selectedImage:[UIImage imageNamed:@"paper_tab_item_active.png"]];
view4.tabBarItem =
[[UITabBarItem alloc] initWithTitle:@"More"
image:[UIImage imageNamed:@"menu_tab_item.png"] selectedImage:[UIImage imageNamed:@"menu_tab_item_active.png"]];
在 HomePagingViewController
ViewDidLoad
中,我按照代码
-(void)navigationSetUp{
self.navigationController.navigationBar.translucent=NO;
UIBarButtonItem * settingBtn=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"settings.png"] style:UIBarButtonItemStylePlain target:self action:@selector(menuHandler:)];
UIBarButtonItem * searchBtn=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"settings.png"] style:UIBarButtonItemStylePlain target:self action:@selector(menuHandler:)];
self.navigationItem.leftBarButtonItem = settingBtn;
self.navigationItem.rightBarButtonItem = searchBtn;
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ie_New_logo.png"]];
}
在此之后,当我更改 HomePagingViewController
的选项卡时,导航右侧按钮放置不正确,右侧没有边距。
参考图片:
请帮忙。
我解决了这个问题,代码没有问题。实际上对于 Epaper 我们使用第三方 SDK 所以这个问题 occur.I 删除了 SDK & 代码现在工作正常。
你应该想想UIBarButtonSystemItemFixedSpace
效果。
- 例如:
UIBarButtonItem * space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
--
- 为什么要用系统导航栏?自定义导航栏就好了!赞:https://github.com/chenliangloveyou/EasyNavigation