不要急,不要怕

oc,UI基础

//关闭导航栏的半透明状态
self.navigationController.navigationBar.translucent = NO;
//设置导航栏颜色
[self.navigationController.navigationBar setBarTintColor:[UIColor blackColor]];
//关闭自适配
self.automaticallyAdjustsScrollViewInsets = NO;
//改变状态栏颜色
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];

self.view.backgroundColor = [UIColor orangeColor];

//改变导航条的颜色
[self.navigationController.navigationBar setBarTintColor:[UIColor redColor]];
//这个设颜色有点坑
// [self.navigationController.navigationBar setBackgroundColor:[UIColor redColor]];
//设置背景图片
//[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@”1.png”] forBarMetrics:UIBarMetricsDefault];
//去掉导航条下面的线 最好配合 设置背景图片一起用(背景图用纯色的图片)
//[self.navigationController.navigationBar setShadowImage:[UIImage imageNamed:@”touming.png”]];

//self.title = @”主页”;//主要用这个
//self.navigationItem.title = @”主页”;
//这个无效
//self.navigationController.title = @”主页”;
//设置导航标题颜色
//这个是老方法 5.0的方法
//NSForegroundColorAttributeName
// [self.navigationController.navigationBar setTitleTextAttributes:@{UITextAttributeTextColor:[UIColor whiteColor]}];
//新方法 7.0出的
// [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
//我们发现设置系统的是不兼容的
// [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:30.0f]}];
//怎么判断手机版本
//获取当前手机的系统版本号
//[[UIDevice currentDevice].systemVersion floatValue]

// if ([[UIDevice currentDevice].systemVersion floatValue]>=7.0) {
// [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
// }else{
// [self.navigationController.navigationBar setTitleTextAttributes:@{UITextAttributeTextColor:[UIColor whiteColor]}];
// }

//我想放一个自定义的标题
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
label.text = @”自定义标题”;
label.font = [UIFont boldSystemFontOfSize:25.0f];
label.textColor = [UIColor greenColor];
label.textAlignment = NSTextAlignmentCenter;
// [self.navigationController.navigationBar addSubview:label];
//把我们的标题label 放上去
self.navigationItem.titleView = label;

//设置导航栏的按钮
// UIButton
/

系统的
UIBarButtonSystemItemDone,
UIBarButtonSystemItemCancel,
UIBarButtonSystemItemEdit,
UIBarButtonSystemItemSave,
UIBarButtonSystemItemAdd,
UIBarButtonSystemItemFlexibleSpace,
UIBarButtonSystemItemFixedSpace,
UIBarButtonSystemItemCompose,
UIBarButtonSystemItemReply,
UIBarButtonSystemItemAction,
UIBarButtonSystemItemOrganize,
UIBarButtonSystemItemBookmarks,
UIBarButtonSystemItemSearch,
UIBarButtonSystemItemRefresh,
UIBarButtonSystemItemStop,
UIBarButtonSystemItemCamera,
UIBarButtonSystemItemTrash,
UIBarButtonSystemItemPlay,
UIBarButtonSystemItemPause,
UIBarButtonSystemItemRewind,
UIBarButtonSystemItemFastForward,
UIBarButtonSystemItemUndo
/
//UIBarButtonItem
item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(itemClick)];
// self.navigationController.
//self.navigationItem.leftBarButtonItem = item;
//设颜色
//[self.navigationItem.leftBarButtonItem setTintColor:[UIColor whiteColor]];

UIButton but = [UIButton buttonWithType:UIButtonTypeCustom];
but.frame = CGRectMake(0, 0, 35, 35);
[but setBackgroundImage:[UIImage imageNamed:@”tab_call_nor@2x.png”] forState:UIControlStateNormal];
[but addTarget:self action:@selector(butClick) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem
butItem = [[UIBarButtonItem alloc] initWithCustomView:but];
self.navigationItem.rightBarButtonItem = butItem;

}

  • (void)butClick{
    NSLog(@”自定义导航按钮”);

TwoViewController *vc = [[TwoViewController alloc] init];
//使用代理
vc.delegate = self;
[self.navigationController pushViewController:vc animated:YES];
}

//实现代理方法

  • (void)changeColor:(UIColor *)color{

self.view.backgroundColor = color;

}

  • (void)itemClick{
    NSLog(@”点击了放大镜”);
    }

  • (void)touchesBegan:(NSSet )touches withEvent:(UIEvent )event{

TwoViewController *vc = [[TwoViewController alloc] init];
vc.delegate = self;
[self.navigationController pushViewController:vc animated:YES];

//没有导航条的话 你可以用这样的方式跳转
//[self presentViewController:vc animated:YES completion:nil];
//没有导航条的返回方法;
[self dismissViewControllerAnimated:YES completion:nil];
self.navigationController.navigationBarHidden = YES;
[self.navigationController popViewControllerAnimated:YES];

//给tabbar加下标
for (int i = 0; i<self.viewControllers.count; i++) {
UITabBarItem *item = self.tabBar.items[i];
if (i==2) {
item.badgeValue = @”7”;
}
}