ios - 自定义 UI 导航栏和按钮

标签 ios objective-c user-interface ios7 uikit

你好我是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/

相关文章:

c++ - Qt - QProcess 不工作

android - 使每部手机的用户界面通用

ios - 同时发送 ibeacon 和 eddystone 数据包

加载时 jQuery UI Accordion "jumps"

ios - UIActivityViewController 主题不适用于 Outlook

ios - 如何在MapView中绘制GMSPolyline

objective-c - 为什么这个 subview 没有被删除?

ios - NSMutableArray 集合和@Synchronized block

应用暂停时的 iOS 通知

ios - Q :How to get CGPoint from NSConcreteValue?