我使用以下代码在Swift中实现了分享按钮:
@IBAction func share(_ sender: UIBarButtonItem) {
let textToShare = [ "Text to share" ]
let activityViewController = UIActivityViewController(activityItems: textToShare, applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
self.present(activityViewController, animated: true, completion: nil)
}
答案 0 :(得分:2)
使用以下代码更改应用中的导航栏色调颜色:
{p}AppDelegate
didFinishLaunchingWithOptions
中的
UINavigationBar.appearance().tintColor = UIColor.red
用要在按钮中设置的颜色替换红色。
答案 1 :(得分:0)
我在iOS 11上遇到了同样的问题,该解决方案对我来说虽然不是很好,但对我来说却是很好。
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[UINavigationBar appearance] setTranslucent:YES];
[[UINavigationBar appearance] setBackgroundColor:[UIColor blackColor]];
[[UINavigationBar appearance] setTitleTextAttributes:@{
NSForegroundColorAttributeName: [UIColor blackColor]
}];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[UINavigationBar appearance] setTranslucent:NO];
//set your app color
[[UINavigationBar appearance] setBackgroundColor:[UIColor APPCOLOR]];
[[UINavigationBar appearance] setTitleTextAttributes:@{
NSForegroundColorAttributeName: [UIColor APPCOLOR]
}];
}
PS:我也尝试了THIS解决方案,但不适用于我。