zoukankan      html  css  js  c++  java
  • UINavigationBar 上面添加多个按钮

    http://xiaohui3837843.blog.163.com/blog/static/54388740201111615432445/

    此方法已经验证,可行

    UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 150, 45)]; 
    [tools setTintColor:[self.navigationController.navigationBar tintColor]]; 
    [tools setAlpha:[self.navigationController.navigationBar alpha]]; 
    NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:2];

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

    UIBarButtonItem *anotherButton1 = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UITabBarSystemItemContacts 
                                                            target:self action:@selector(clickEdit:)]; 
    [buttons addObject:anotherButton]; 
    [anotherButton release]; 
    [buttons addObject:anotherButton1]; 
    [anotherButton1 release]; 
    [tools setItems:buttons animated:NO]; 
    [buttons release]; 
    UIBarButtonItem *myBtn = [[UIBarButtonItem alloc] initWithCustomView:tools]; 
    self.navigationItem.rightBarButtonItem = myBtn;

    [myBtn release]; 
    [tools release];

     

     

     

    http://blog.sina.com.cn/s/blog_677089db0100um5p.html

    次方法验证,暂时不可行,没查明原因

    UIView * rightButtonParentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
     

      rightButtonParentView.backgroundColor = [UIColor clearColor];
        
        int buttonSize = 32;
        int rightOffset = 20;
        UIButton * setButton = [[UIButton alloc] initWithFrame:CGRectMake(rightButtonParentView.frame.size.width - buttonSize - rightOffset, 6, buttonSize, buttonSize)];
        [setButton setBackgroundImage:[UIImage imageNamed:@"star.png"] forState:UIControlStateNormal];
        [setButton addTarget:self action:@selector(NSlog) forControlEvents:UIControlEventTouchUpInside];
        [rightButtonParentView addSubview:setButton];
        [setButton release];
        
        UIButton * searchButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 6, buttonSize, buttonSize)];
        [searchButton setBackgroundImage:[UIImage imageNamed:@"star.png"] forState:UIControlStateNormal];
        [searchButton addTarget:self action:@selector(NSlog) forControlEvents:UIControlEventTouchUpInside];
        [rightButtonParentView addSubview:searchButton];
        [searchButton release];
        
        
        UIBarButtonItem * rightButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButtonParentView];
        [rightButtonParentView release];                            
        self.navigationItem.rightBarButtonItem = rightButtonItem;
        [rightButtonItem release];
  • 相关阅读:
    bzoj2733 永无乡 平衡树按秩合并
    bzoj2752 高速公路 线段树
    bzoj1052 覆盖问题 二分答案 dfs
    bzoj1584 打扫卫生 dp
    bzoj1854 游戏 二分图
    bzoj3316 JC loves Mkk 二分答案 单调队列
    bzoj3643 Phi的反函数 数学 搜索
    有一种恐怖,叫大爆搜
    BZOJ3566 概率充电器 概率dp
    一些奇奇怪怪的过题思路
  • 原文地址:https://www.cnblogs.com/easonoutlook/p/2642851.html
Copyright © 2011-2022 走看看