您的位置:首页 > 移动开发 > Objective-C

object-ocUI之导航控件

2015-11-24 13:18 573 查看
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];

    
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  导航 ios开发 控件