• UINavigationController和UIBarButtonItem的例子


    #import "AppDelegate.h"

    #import "FirstViewController.h"

    #import "SecondViewController.h"

    @interface AppDelegate ()

    @end

    @implementation AppDelegate

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

    {

        //创建导航栏视图

        UINavigationController *navc1=[[UINavigationController alloc] initWithRootViewController:[FirstViewController new]];

        //分栏名字

        navc1.tabBarItem.title=@"消息";

        //提示消息

        navc1.tabBarItem.badgeValue=@"2";

        //添加图片

        navc1.tabBarItem.image=[UIImage imageNamed:@"1"];

        

        UINavigationController *navc2=[[UINavigationController alloc] initWithRootViewController:[SecondViewController new]];

        navc2.title=@"动态";

        navc2.tabBarItem.badgeValue=@"2";

        //创建分栏

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

        //将两个导航栏添加到底部视图

        tab.viewControllers=@[navc1,navc2];

        navc2.tabBarItem.image=[UIImage imageNamed:@"2"];

        //添加前景色

        tab.tabBar.tintColor=[UIColor greenColor];

        //将底部视图添加到根视图上

        self.window.rootViewController=tab;

           return YES;

    }

    #import <UIKit/UIKit.h>

    #import "SecondViewController.h"

    @interface FirstViewController : UIViewController

    @end

    #import "FirstViewController.h"

    @interface FirstViewController ()

    @end

    @implementation FirstViewController

    - (void)viewDidLoad

    {

        [super viewDidLoad];

        //更换背景色

        self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"20141110_f64c52ed5be2176adaa1mADR4skv4nYU.jpg"]];

        //添加标题

        self.title=@"第一个视图";

        //更换标题的前景色

        self.navigationController.navigationBar.titleTextAttributes=@{NSForegroundColorAttributeName:[UIColor yellowColor]};

        //创建一个导航栏按钮

        UIBarButtonItem *Tab=[[UIBarButtonItem alloc] initWithTitle:@"next" style:2 target:self action:@selector(Next)];

        //更改前景色

        Tab.tintColor=[UIColor redColor];

        //添加右边按钮

        self.navigationItem.rightBarButtonItem=Tab;

    }

    -(void)Next

    {

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

        //导航栏视图 :推到下一页

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

    }

    #import "SecondViewController.h"

    @interface SecondViewController ()

    @end

    @implementation SecondViewController

    - (void)viewDidLoad

    {

        [super viewDidLoad];

        self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"8efce6cd7b899e51feb2371b40a7d933c8950d83.jpg"]];

        self.title=@"第二个视图";

        self.navigationController.navigationBar.titleTextAttributes=@{NSForegroundColorAttributeName:[UIColor greenColor]};

      UIBarButtonItem *tab=[[UIBarButtonItem alloc] initWithTitle:@"back" style:2 target:self action:@selector(BackPage)];

        self.navigationItem.leftBarButtonItem=tab;

        

    }

    -(void)BackPage

    {

        //出栈 返回到上一页

        [self.navigationController popViewControllerAnimated:YES];

    }

  • 相关阅读:
    【Android】ContentValues的用法
    【Android】Android处理Home键方法小结
    【Android】spannableStringBuilder
    【Android】Android 4.0 Launcher2源码分析——启动过程分析
    【Android】android文件的写入与读取---简单的文本读写context.openFileInput() context.openFileOutput()
    【Android】Android取消EditText自动获取焦点
    android在view.requestFocus(0)返回false的解决办法
    Android中创建倒影效果的工具类
    android布局layout中的一些属性
    android中巧妙更改spinner、AutoCompleteTextView分割线的颜色值(spinner AutoCompleteTextView divider color)
  • 原文地址:https://www.cnblogs.com/tmf-4838/p/5281464.html
Copyright © 2020-2023  润新知