object-ocUI之导航控件

来源:互联网 发布:梦幻西游高级宝石算法 编辑:程序博客网 时间:2024/06/05 14:29

1.删除系统自己给我们的main.board。和viewCollorer.h/.m文件 ,info.plist删除main

2.appDelegate.m

//手动创建window

    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

    self.window.backgroundColor = [UIColor whiteColor];


//创建导航控制器

    UINavigationController *naviga = [[UINavigationController alloc]initWithRootViewController:[[MYViewController alloc]init]];

    //设置下面导航条图片

    naviga.tabBarItem.image = [UIImage imageNamed:@"tab1.png"];


//创建标签控制器(width:49)

    UITabBarController *MytabBar = [[UITabBarController alloc]init];

    //添加到MytabBar

    MytabBar.viewControllers = @[naviga,twoNavi,threeNavi];

//为了让他能启动加载这个window

    [self.window makeKeyAndVisible];


3.创建导航右边和左边的按钮

    首先定义按钮(系统自定义

//创建右边按钮

    UIBarButtonItem *btnGO = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(ClickedItem:)];

//自定义按钮用自定义按钮方法

    UIBarButtonItem *btnUP = [[UIBarButtonItem alloc]initWithTitle:@"编辑" style:UIBarButtonItemStylePlain target:self action:@selector(ClickedItem:)];

 //自定义设置导航默认的返回按钮

    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:nil];

//改变图片返回按钮

    [self.navigationController.navigationBar setBackIndicatorImage:[UIImage imageNamed:@"back_btn.png"]];

    [self.navigationController.navigationBar setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"back_btn.png"]];

    //自动以颜色按钮

    [self.navigationController.navigationBar setTintColor:[UIColor purpleColor]];

    //设置导航条按钮

    [self.navigationController.navigationBar setBarTintColor:[UIColor orangeColor]];

    //设置字体大小

    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:25],NSForegroundColorAttributeName:[UIColor blueColor]}];


4.使用导航页面跳转


    SecondViewController *twoView = [[SecondViewController alloc]init];

    //页面跳转

    [self.navigationController pushViewController:twoView animated:YES];


5.页面回跳

//返回到最主页,弹出当前控制器,或者跳到指定页面

    [self.navigationController popToRootViewControllerAnimated:YES];

    

0 0