糖糖的iOS专题

如何在导航栏的右上角加两个item

2016-10-25  本文已影响7人  天堂秀

如何在导航栏的右上角加两个item

@property(nonatomic,strong)UIButton*anotherButton;

@property(nonatomic,strong)UIButton*anotherButton2;

-(void)viewDidLoad的方法下写UIBarButtonSystemItem

UIBarButtonItem*anotherButton = [[UIBarButtonItemalloc]initWithImage:[UIImageimageNamed:@"header_partook"]style:UIBarButtonItemStylePlaintarget:selfaction:@selector(shardBtn:)];

UIBarButtonItem*anotherButton2 = [[UIBarButtonItemalloc]initWithImage:[UIImageimageNamed:@"header_keep"]style:UIBarButtonItemStylePlaintarget:selfaction:@selector(did:)];

[self.navigationItemsetRightBarButtonItems:[NSArrayarrayWithObjects: anotherButton,anotherButton2,nil]];

-(void)shardBtn:(UIButton*)btn{

NSLog(@"---shardBtn---");

}

-(void)did:(UIButton*)btn{

NSLog(@"---did---");

}

效果图:

一个item的情况

UIBarButtonItem*rightBarItem = [[UIBarButtonItemalloc]initWithImage:[UIImageimageNamed:@"header_partook"]style:UIBarButtonItemStylePlaintarget:selfaction:@selector(shardBtn)];

self.navigationItem.rightBarButtonItem= rightBarItem;

上一篇 下一篇

猜你喜欢

热点阅读