简体   繁体   English

如何将按钮添加到导航栏

[英]How to add button to NavigationBar

I want to add button like this one to share tweet: image我想添加这样的按钮来分享推文:图片

Here is what I would like to call:这是我想调用的:

[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"twitter://"]];

You can add a button to the UINavigationItem like this:您可以像这样向UINavigationItem添加一个按钮:

- (void)loadView {
    [super loadView];
    
    UIImage *hearthImage = [UIImage imageNamed:@"heart" inBundle:[NSBundle bundleForClass:[self class]]];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:hearthImage style:UIBarButtonItemStylePlain target:self action:@selector(tapButton:)];
}

- (void) tapButton: (id) sender {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://twitter.com/intent/tweet?text=YOUR_TEXT_HERE"]]];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM