如何在uitoolbar上以编程方式添加uibarbutton?

时间:2016-02-01 12:37:43

标签: ios objective-c uibarbuttonitem uitoolbar

enter image description here

这是我的UIToolbar,我想将TwitterWhatsapp UIBarbutton合并为一个。

我用Google搜索,但我只收到UINavigationController的信息。

是否有预定义的方法,或者我需要自定义它?

1 个答案:

答案 0 :(得分:0)

喜欢

UIBarButtonItem *TwitterButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(SocialAction:)];
TwitterButtonItem.tag = 1;

UIBarButtonItem *WhatsAppButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(SocialAction:)];
WhatsAppButtonItem.tag = 2;

yourtoolBar.items = [NSArray arrayWithObjects:WhatsAppButtonItem,TwitterButtonItem, nil];

得像

- (Void)SocialAction:(UIBarButtonItem *)button {
NSLog(@"%i", button.tag);
 // based on tag continue your work
}