如何在NavigationBar中添加按钮

时间:2020-09-06 23:24:36

标签: ios objective-c theos

我想添加这样的按钮以分享tweet:image

这就是我想打电话的内容

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

1 个答案:

答案 0 :(得分:0)

您可以像这样向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"]]];
}
相关问题