ios - 如何将按钮添加到导航栏
问题描述
我想添加这样的按钮来分享推文:图片
这是我想调用的:
[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"twitter://"]];
解决方案
您可以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"]]];
}
推荐阅读
- python - 通过最小化迭代次数来改进代码
- clojurescript - CLJS: CompilerException java.lang.RuntimeException: Feature 应该是一个关键字
- python - 如何在 Python 中过滤具有其他日期的日期数据框?
- python - 如何从 txt 文件创建一个 numpy 数组
- c# - 无法读取 json 来自 C# 中的 Web API
- android - 通知不可见或未到来
- json - 使用 laravel json 导入双引号
- angular - Angular @HostListener 事件多次触发
- batch-file - 当位置是动态的时,寻找一个 Batchfile 脚本来删除一个文件夹
- javascript - 如何比较日期并执行以下代码?