你好我是ios开发新手,想知道如何自定义导航栏按钮
这是我用来改变导航栏颜色的东西
[[UINavigationBar appearance] setBarTintColor:[UIColor]]
我想改变按钮的颜色
最佳答案
首先您需要设置导航栏,假设您的第一个屏幕是 SpalshViewController,您需要将启动画面设置为导航栏的 Root View Controller ,然后将导航栏设置为 Root View Controller ,如:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
SplashScreenVC *obj =[CustomUtility getViewController:@"SplashScreenVC"];
self.navigationController =[[UINavigationController alloc] initWithRootViewController:obj];
self.window.rootViewController =self.navigationController;
在 didFinishLaunchingWithOptions
中
现在来定制你需要设置的导航栏设置和外观:
self.navigationController.navigationBar.translucent = NO;
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"top_bg2.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor],NSFontAttributeName:[UIFont fontWithName:@"Lato-Regular" size:18]}];
现在为导航栏设置自定义栏按钮,您需要创建栏按钮项目,例如:
UIBarButtonItem *leftbtn;
UIBarButtonItem *rightbtn;
[self.navigationController.navigationItem setLeftBarButtonItem:leftbtn];
[self.navigationController.navigationItem setRightBarButtonItem:rightbtn];
根据您的需要自定义barbuttonItems
如果你想在导航栏上设置多个按钮,你可以这样添加:
UIBarButtonItem *leftbtn1;
UIBarButtonItem *leftbtn2;
UIBarButtonItem *rightbtn1;
UIBarButtonItem *rightbtn2;
[self.navigationController.navigationItem setLeftBarButtonItems:@[leftbtn1,leftbtn2]];
[self.navigationController.navigationItem setRightBarButtonItems:@[rightbtn1,rightbtn2]];
希望对你有所帮助
关于ios - 自定义 UI 导航栏和按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34447287/