导航栏(Navigation)上多个点击事件

来源:互联网 发布:淘宝的模特是怎么找的 编辑:程序博客网 时间:2024/06/07 05:05

在开发中经常会出现导航栏右侧需要两个或者三个点击事件,这样就需要设置多个点击事件。


代码:

  UIToolbar *tools=[[UIToolbar alloc]initWithFrame:CGRectMake(5, 0, 120, 45)];    //解决出现的那条线    tools.clipsToBounds = YES;    //解决tools背景颜色的问题    [tools setBackgroundImage:[UIImage new]forToolbarPosition:UIBarPositionAny                      barMetrics:UIBarMetricsDefault];    [tools setShadowImage:[UIImage new]       forToolbarPosition:UIToolbarPositionAny];    //添加两个button    NSMutableArray*buttons=[[NSMutableArray alloc]initWithCapacity:2];    //第一个按钮    UIBarButtonItem *button1=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@""] style: UIBarButtonItemStyleDone target:self action:@selector(shareTaepd:)];    //设置title    [button1 setTitle:@"分享"];     //设置title颜色    [button1 setTintColor:[UIColor blackColor]];    UIBarButtonItem *button2=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@""] style: UIBarButtonItemStyleDone target:self action:@selector(releaseTaepd:)];    [button2 setTintColor:[UIColor blackColor]];    [button2 setTitle:@"发布"];    [buttons addObject:button1];    [buttons addObject:button2];    [tools setItems:buttons animated:NO];    UIBarButtonItem*btn=[[UIBarButtonItem    alloc]initWithCustomView:tools];    self.navigationItem.rightBarButtonItem=btn;

这样实现方法shareTaepd: 和releaseTaepd:就可以分别完成点击分享和发布的点击事件了。

0 0
原创粉丝点击