zoukankan      html  css  js  c++  java
  • 自定义UINavigationItem的两种方法以及相应的隐藏方法

    转自:http://www.cnblogs.com/wengzilin/p/3534315.html

    第一种:

    UIImage *searchimage=[UIImage imageNamed:@"search.png"];

        UIBarButtonItem *barbtn=[[[UIBarButtonItem alloc] initWithImage:nil style:UIBarButtonItemStyleDone target:self action:@selector(searchprogram)] autoRelease];    

        barbtn.image=searchimage;

        self.navigationItem.rightBarButtonItem=barbtn;

    这种设置出来的item图片跟大小是固定的

    其隐藏方法是:在需要隐藏的时候self.navigationItem.xxxItem = nil;

    显示方法是重新alloc-init一次;

    第二种: 

    IButton*rightButton = [[UIButtonalloc]initWithFrame:CGRectMake(0,0,30,30)];

        [rightButtonsetImage:[UIImageimageNamed:@"search.png"]forState:UIControlStateNormal];

        [rightButtonaddTarget:selfaction:@selector(searchprogram)forControlEvents:UIControlEventTouchUpInside];

       UIBarButtonItem*rightItem = [[UIBarButtonItemalloc]initWithCustomView:rightButton];

        [rightButton release];

       self.navigationItem.rightBarButtonItem= rightItem;

        [rightItem release];

    这种方式设计出来的item比较灵活,尤其是在 隐藏显示的时候:

    隐藏方法:self.navigationItem.xxxItem.customView.hidden =YES;

    显示方法,同上xxx.hidden = NO;

    这种方式更合理一些,因为不需要不断的创建/消除,所以推荐用这种方法!

    第三种:

    UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(methodtocall:) ]; 

  • 相关阅读:
    测试驱动开发的意义何在
    Web自动化测试模式page object的小利器:gizmo
    在NANT使用Nunit2标签运行Nunit测试
    小试牛刀 Ruby on Rails
    敏捷回顾会议的思考
    ThoughtWorks技术校园行第二波 课程资料 CleanCode&DirtyCode
    从git merge 和 git rebase想到……
    Ruby中的深浅拷贝
    NUnit Extension小介绍
    如何写好的测试呢?
  • 原文地址:https://www.cnblogs.com/wangpei/p/3759188.html
Copyright © 2011-2022 走看看