博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS 设置导航栏之二(设置导航栏的颜色、文字的颜色、左边按钮的文字及颜色)...
阅读量:5282 次
发布时间:2019-06-14

本文共 3270 字,大约阅读时间需要 10 分钟。

                             

#import 
@interface AppDelegate : UIResponder
@property (strong, nonatomic) UIWindow *window;@end
#import "AppDelegate.h"#import "KeyViewController.h"@interface AppDelegate ()@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];    // Override point for customization after application launch.    self.window.backgroundColor = [UIColor whiteColor];    //初始化导航    UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:[[KeyViewController alloc] init]];        //设置导航栏的背景颜色(iOS7之后)    [[UINavigationBar appearance] setBarTintColor:[[UIColor alloc] initWithRed:133/255.0 green:0 blue:47/255.0 alpha:1]];        //使用背景图片来设置导航栏的颜色(iOS7之后)//    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"顶栏背景"] forBarMetrics:UIBarMetricsDefault];        //设置导航栏上文字的颜色(iOS7之后)    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor orangeColor]}];    self.window.rootViewController = navi;        [self.window makeKeyAndVisible];    return YES;}@end
#import 
@interface KeyViewController : UIViewController@end
#import "KeyViewController.h"#import "CashViewController.h"@interface KeyViewController ()@end@implementation KeyViewController- (void)viewDidLoad {    [super viewDidLoad];    self.title = @"提取现金";    UIButton *getCashBtn = [UIButton buttonWithType:UIButtonTypeCustom];    getCashBtn.frame = CGRectMake(100, 100, 120, 45);    [getCashBtn setTitle:@"下一页面" forState:0];    getCashBtn.backgroundColor = [UIColor orangeColor];    [getCashBtn addTarget:self action:@selector(getCashAction:) forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:getCashBtn];}- (void)getCashAction:(UIButton *)sender{    CashViewController *cashVC = [[CashViewController alloc] init];    [self.navigationController pushViewController:cashVC animated:YES];}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}@end
#import 
@interface CashViewController : UIViewController@end
#import "CashViewController.h"@interface CashViewController ()@end@implementation CashViewController- (void)viewDidLoad {    [super viewDidLoad];    self.title = @"银行卡绑定";    self.view.backgroundColor = [UIColor whiteColor];        //使用图片来设置导航栏左边的按钮//    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"返回按钮"] style:UIBarButtonItemStylePlain target:self action:@selector(goBackAction:)];        //设置导航栏左边按钮的文字    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithTitle:@"< 返回" style:UIBarButtonItemStylePlain target:self action:@selector(goBackAction:)];        //设置导航栏左边按钮文字的颜色(以及背景图片的颜色)    leftItem.tintColor = [UIColor whiteColor];    self.navigationItem.leftBarButtonItem = leftItem;}/** *  点击导航栏左边按钮所触发的事件 */- (void)goBackAction:(UIButton*)sender{    [self.navigationController popViewControllerAnimated:YES];}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    }@end

 

转载于:https://www.cnblogs.com/lantu1989/p/5076035.html

你可能感兴趣的文章
Luogu_4103 [HEOI2014]大工程
查看>>
Oracle——SQL基础
查看>>
项目置顶随笔
查看>>
Redis的安装与使用
查看>>
P1970 花匠
查看>>
java语言与java技术
查看>>
NOIP2016提高A组五校联考2总结
查看>>
iOS 项目的编译速度提高
查看>>
table中checkbox选择多行
查看>>
Magento开发文档(三):Magento控制器
查看>>
性能调优攻略
查看>>
ie6解决png图片透明问题
查看>>
瞬间的永恒
查看>>
2019-8-5 考试总结
查看>>
JS中实现字符串和数组的相互转化
查看>>
web service和ejb的区别
查看>>
Windows Azure Cloud Service (29) 在Windows Azure发送邮件(下)
查看>>
微信上传素材返回 '{"errcode":41005,"errmsg":"media data missing"}',php5.6返回
查看>>
div或者p标签单行和多行超出显示省略号
查看>>
Elasticsearch 滚动重启 必读
查看>>