UINavigationController导航控制器

来源:互联网 发布:dbc2000麻痹戒指数据 编辑:程序博客网 时间:2024/05/17 05:17


-------------------------------------------------------------------------

//(初始化)导航栏竖屏44,还有20的标题,横屏32

//iPhone : 竖屏 44 横屏 32,iPad: 44

     UINavigationController * navVC = [[UINavigationController alloc] initWithRootViewController:firstVC];


//导航栏透明度(默认半透明)
navVC.navigationBar.translucent = NO;
//返回键的颜色
    navVC.
navigationBar.tintColor = [UIColor whiteColor];
//导航栏背景色
    navVC.
navigationBar.barTintColor = [UIColor greenColor];

//是否隐藏导航栏
navVC.navigationBarHidden = NO
;
//导航栏设置背景图
//如果图片的尺寸是320*44,则图片显示在导航栏上
//如果图片尺寸是320* 64,则图片从状态栏开始显示
//如果两个都不是,则从状态栏开始平铺图片
    [navVC.
navigationBar setBackgroundImage:[UIImage imageNamed:@"title_bg.png"] forBarMetrics:UIBarMetricsDefault];




//设置背景色,不设可能产生BUG;
   
 self.view.backgroundColor = [UIColor redColor];
//设置标题
   
 self.navigationItem.title = @"首页";

//在导航栏添加按钮
   
 self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(bar)] autorelease];
//法二
self.navigationItem.rightBarButtonItem = self.editButtonItem;

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [
super setEditing:editing animated:animated];
    [
self.tabBarController setEditing:editing animated:YES];
}

//是否隐藏返回按钮
   
 self.navigationItem.hidesBackButton = YES;
//推向下一页
[self.navigationController pushViewController:deta animated:YES];
//几种翻页时效果(魔态)[枚举]
deta.modalTransitionStyle = UIModalPresentationPageSheet;
//点按钮弹出一个视图或视图控制器(魔态)
    [
self presentViewController:detaVC(下一页面) animated:YES completion:^{NSLog(@"finishi ");}];
//到下一页返回(取消弹出)
- (void)dismissPage
{
    [
self dismissViewControllerAnimated:YES completion:^{}];
}



//返回到首页
    [
self.navigationController popToRootViewControllerAnimated:YES];
//返回到上一层
    [
self.navigationController popViewControllerAnimated:YES];
//返回到指定界面
    [
self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];

//再所有页面中找到tabView,reloadData刷新页面
       
 NSArray *allControllers = self.navigationController.viewControllers;
//找到指定页面
       
 UITableViewController *tableViewController = [allControllers objectAtIndex:[allControllers count]-2];
        [tableViewController.
tableView reloadData];//刷新页面


修改navigationBar title的背景颜色 

 

这个方法在iOS5以后可以这样用

navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor yellowColor] forKey:UITextAttributeTextColor];

 

通过以下key值修改起属性

UITextAttributeFont

UITextAttributeTextShadowOffset

UITextAttributeTextShadowColor 






































0 0