如何在使用FBSDK共享对话框时更改UIBarButtonItem的色调颜色

时间:2017-02-27 11:28:30

标签: ios objective-c uinavigationbar uibarbuttonitem fbsdk

我遇到了UIBarButtonItem tintColor的问题。

我已在AppDelegate中设置[[UIBarButtonItem appearance] setTintColor:[UIColor whiteColor]];,以便在应用中使用默认颜色

但是在这个屏幕上。它似乎看不到按钮,因为它是白色的! 我使用FBSDKShareDialog showFromViewController来显示共享弹出屏幕。如何为此屏幕编辑tintColor?

编辑以解释更多信息。

作为建议,它仅适用于此屏幕。但实际上我的问题是在我将此屏幕更改为蓝色后。它会影响发送电子邮件屏幕。所以在电子邮件屏幕上似乎看不到按钮,因为我的导航栏是蓝色。那是诡计多端的。我使用UIActicityController来呈现电子邮件屏幕。

enter image description here

2 个答案:

答案 0 :(得分:0)

目标c

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window.tintColor = [UIColor whiteColor];
return YES; 
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if([UINavigationBar conformsToProtocol:@protocol(UIAppearanceContainer)]) {
    [UINavigationBar appearance].tintColor = [UIColor whiteColor];
}

return YES;
}

// *********** *********

<强>夫特

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
self.window?.tintColor = UIColor.white
return true
}

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if UINavigationBar is UIAppearanceContainer {
    UINavigationBar.appearance().tintColor = UIColor.white
}
return true
}

答案 1 :(得分:0)

如果你仍然没有想到这一点,你可以做的就是使用FBSDKSharing的代表。

- (IBAction)shareOnFacebook:(id)sender
{
    FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
    content.contentTitle = @"Content Title";
    content.contentURL = [NSURL URLWithString:@"https://example.com/url/to/your/app"];
    content.quote = @"Learn quick and simple ways for people to share content from your app or website to Facebook.";

    // make the changes here; what you want to see in FB Dialog
    [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];

    FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
    dialog.fromViewController = self;
    dialog.shareContent = content;
    dialog.mode = FBSDKShareDialogModeShareSheet;
    dialog.delegate = self;
    [dialog show];
}

// And change it back in these delegate methods
-(void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
}

-(void)sharerDidCancel:(id<FBSDKSharing>)sharer
{
}

-(void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
}