How to add button to NavigationBar

23 Views Asked by At

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://"]];
1

There are 1 best solutions below

0
Itay Brenner On

You can add a button to the UINavigationItem like this:

- (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"]]];
}