码迷,mamicode.com
首页 > 其他好文 > 详细

设置菜单和工具条

时间:2014-09-30 21:28:10      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   sp   div   c   on   

代码:

可任选一套方法进行显示和隐藏,如果决定有动画的那套,那么一开始初始化时就必须用set方法进行控制

-(void) setBar
{
    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:nil];
    
    UIBarButtonItem *searchButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:nil];
    
    self.navigationItem.leftBarButtonItems = @[addButton, searchButton];
    
    UIBarButtonItem *organizeButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemOrganize target:self action:nil];
    
    [self setToolbarItems:@[organizeButton]];
}

-(void) showBar
{
    // 无论哪套设置方法都可以这么判断是否隐藏
    if (self.navigationController.navigationBar.hidden)
    {
        NSLog(@"show it");
        
        // 两套隐藏方法,这套无动画,不可混用
        //self.navigationController.navigationBar.hidden = NO;
        //self.navigationController.toolbar.hidden = NO;
        
        // 有动画
        [self.navigationController setNavigationBarHidden:NO animated:YES];
        [self.navigationController setToolbarHidden:NO animated:YES];
        
    }
    else
    {
        NSLog(@"hide it");
        [self.navigationController setNavigationBarHidden:YES animated:YES];
        [self.navigationController setToolbarHidden:YES animated:YES];
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setBar];
    
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self showBar];
}

 

设置菜单和工具条

标签:style   blog   color   io   ar   sp   div   c   on   

原文地址:http://www.cnblogs.com/code-style/p/4002417.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!