我还没有找到我喜欢的机制,所以这是我的。部分问题在于更高版本的 iOS 添加了应用程序添加系统范围共享和操作扩展的功能。这些第三方项目似乎以各种方式编码。有些继承了应用程序的导航栏样式,有些使用自己的,有些似乎假定为白色导航栏(但实际上是从应用程序继承的)。
这是在 iOS 12.2 上测试的。
我创建了一个UIActivityItemSource
,我有:
- (nullable id)activityViewController:(nonnull UIActivityViewController *)activityViewController itemForActivityType:(nullable UIActivityType)activityType {
if (activityType == UIActivityTypePrint || [activityType.lowercaseString containsString:@"extension"] || [activityType containsString:@"AssignToContact"]) {
//What a hack, but the best I can do. Seems some extensions inherit nav style from parent, others don't.
//ActionExtension is bottom row; all those I tested need this. The string comparison catches most non-OS extensions (the type is set by developer).
[[UINavigationBar appearance] setBarTintColor:[UIColor kNavigationBarBackgroundColor]]; //kNavigationBarBackgroundColor is my app's custom nav bar background color
} else {
[[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
}
return self.pdfData; //In my case I'm sharing a PDF as NSData - modify as needed for your shared item
}
然后在我UIActivityViewController
的completionWithItemsHandler
我包括:
[[UINavigationBar appearance] setBarTintColor:[UIColor kNavigationBarBackgroundColor]]; //Again, this is my app's custom nav bar background color
与特定问题无关,但如果您当前没有,则UIActivityItemSource
需要执行以下操作:
NSArray *activities=@[self]; //And set self to be a UIActivityItemSource
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:activities applicationActivities:nil];
我确信这不是 100% 可靠的,但可以与我尝试过的所有扩展一起使用。