bluetooth99 2013-05-09 02:07 采纳率: 0%
浏览 4232
已采纳

UINavigationItem:添加按钮

CSDN移动问答

如何在navigationItem中添加新按钮?需要在右侧按钮附近:

左右按钮:

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_cancelButton];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_shareButton];

再添加一个?

  • 写回答

2条回答

  • redCoral_ 2013-05-09 05:35
    关注

    有很多方法可以实现在右侧添加一个按钮,我认为最简单的方法:

    UIView *buttonView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
    
    UIButton *exampleButton1 = [UIButton buttonWithType:UIButtonTypeCustom];
    exampleButton1.frame = CGRectMake(0, 2, 30, 40);
    [exampleButton1 addTarget:self action:@selector(FirstMethod) forControlEvents:UIControlEventTouchUpInside];
    [exampleButton1 setImage:[UIImage imageNamed:@"image1.png"] forState:UIControlStateNormal];
    [buttonView addSubview:exampleButton1];
    UIButton *exampleButton2 = [UIButton buttonWithType:UIButtonTypeCustom];
    exampleButton2.frame = CGRectMake(70, 2, 30, 40);
    [exampleButton2 addTarget:self action:@selector(Second method) forControlEvents:UIControlEventTouchUpInside];
    [exampleButton2 setImage:[UIImage imageNamed:@"image2.png"] forState:UIControlStateNormal];
    
    [buttonView addSubview:exampleButton2];
    
     self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:buttonView];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗