• IOS NavigationController Toolbar学习笔记


    1、首先将toolbar显示出来,在viewDidLoad中添加代码让toolbar显示,代码如下:

    1. [self.navigationController setToolbarHidden:NO animated:YES]  

         显示如下图:

     

    2、在ToolBar上添加UIBarButtonItem

    新建几个UIBarButtonItem,然后以数组的形式添加到Toolbar中
           

    1. UIBarButtonItem *camera=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(ClickToolBarButton)];  
    2.    [camera setWidth:80];  
    3.    UIBarButtonItem *refresh=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(ClickToolBarButton)];  
    4.    [refresh setWidth:80];  
    5.    UIBarButtonItem *reply=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(ClickToolBarButton)];  
    6.    [reply setWidth:80];  
    7.    UIBarButtonItem *compose=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(ClickToolBarButton)];  
    8.    [compose setWidth:80];  
    9.      
    10.    UIBarButtonItem *splitspace=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];  
    11.      
    12.    [self setToolbarItems:[NSArray arrayWithObjects:splitspace,camera,splitspace,refresh,splitspace,reply,splitspace,compose,splitspace, nil nil]];  


    定义点击事件,代码如下:

    1. -(void)ClickToolBarButton{  
    2.     NSLog(@"你点击了!");  
    3. }  

    最终运行效果图如下:

    说明:使用[self.navigationController setToolbarItems:[NSArray arrayWithObjects:splitspace,camera,splitspace,refresh,splitspace,reply,splitspace,compose,splitspace, nil] animated:YES];添加是不起作用的。

    3、自定义Toolbar,首先新建一个页面,在头文件中声明一下UIToolbar *toolbar;
       在实现文件中的viewDidLoad方法中实现自定义Toolbar,实现代码如下:
     

    1. - (void)viewDidLoad  
    2.   
    3.    [super viewDidLoad];  
    4.    [self.navigationController setToolbarHidden:YES animated:YES];  
    5.    //自定义的UIView  
    6.    UIButton *btn=[UIButton buttonWithType:UIButtonTypeContactAdd];  
    7.      
    8.    [btn addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];  
    9.    UIBarButtonItem *firstButton=[[UIBarButtonItem alloc] initWithCustomView:btn];  
    10.    [firstButton setWidth:120];  
    11.    //系统自带的view  
    12.    UIBarButtonItem *addButton=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:nil];  
    13.    toolbar=[[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-toolbar.frame.size.height-44, self.view.frame.size.width, 44)];  
    14.    [toolbar setBarStyle:UIBarStyleDefault];  
    15.    toolbar.autoresizingMask=UIViewAutoresizingFlexibleTopMargin;  
    16.    [toolbar setItems:[NSArray arrayWithObjects:addButton,firstButton,nil]];  
    17.    [self.view addSubview:toolbar];  
    18.    //Do any additional setup after loading the view from its nib.  



    运行以后界面如下:

  • 相关阅读:
    vuex中store分文件时候index.js进行文件整合
    vuex使用 实现点击按钮进行加减
    页面跳转时候拼接在url后面的多个 参数获取
    vue知识点2018.6.3
    vue项目中,main.js,App.vue,index.html如何调用
    locatin
    Json
    Python3基础 list 访问列表中的列表的元素
    Python3基础 list 索引查看元素
    Python3基础 list 查看filter()返回的对象
  • 原文地址:https://www.cnblogs.com/huangh/p/4061913.html
Copyright © 2020-2023  润新知