【问题标题】:How to change navigation bar and barbuttonitem color & font on Modal view of activity in UIActivityViewController?如何在 UIActivityViewController 中的活动模式视图上更改导航栏和 barbuttonitem 颜色和字体?
【发布时间】:2016-07-08 23:17:46
【问题描述】:

我通过将 Info.plist 中的 view-controller based status bar 设置为 No 将状态栏设置为浅色内容,因为我使用深色作为导航栏。我能够使用AppDelegate.swift 中的以下代码设置导航栏颜色和栏按钮项颜色和字体 -

UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent
    UINavigationBar.appearance().barTintColor = UIColor.darkGrayColor()
    UINavigationBar.appearance().translucent = false


    if #available(iOS 8.2, *) {
        UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName : UIFont.systemFontOfSize(16.0, weight: UIFontWeightThin)], forState: UIControlState.Normal)
        UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName : UIFont.systemFontOfSize(23.0, weight: UIFontWeightThin), NSForegroundColorAttributeName: UIColor.whiteColor()]
    } else {
        // Fallback on earlier versions
    }

    if #available(iOS 9.0, *) {
        UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UINavigationBar.self]).tintColor = UIColor.whiteColor()
        UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UINavigationBar.self]).setTitleTextAttributes([NSFontAttributeName : UIFont.systemFontOfSize(16.0, weight: UIFontWeightThin)], forState: UIControlState.Normal)
    } else {
        // Fallback on earlier versions

    }

我有以下几个问题:-

  1. 我无法为共享活动设置导航栏颜色 - UIActivityViewController 上的 Skype、收件箱(Gmail 邮件应用程序)
  2. 无法设置 barButtonItem,例如使用UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UINavigationBar.self]).setTitleTextAttributes([NSFontAttributeName : UIFont.systemFontOfSize(16.0, weight: UIFontWeightThin)], forState: UIControlState.Normal)“取消”字体和大小

我尝试在 UIActivityViewController 的完成块中编写相同的代码,但没有任何效果。

  1. 当我在 whatsapp 共享活动中从最近聊天中选择一个聊天时,barbuttonitem 颜色变为默认蓝色 - See Snapshot

  2. 首先,我使用的解决方案支持 iOS 8.0、8.2 或更高版本。对于从 7.0 或 7.1 开始的版本,我想实现所有相同的目标。我该怎么做?

【问题讨论】:

    标签: ios uinavigationcontroller uinavigationbar uibarbuttonitem uiactivityviewcontroller


    【解决方案1】:
    // Navigation bar appearance (background and title)
    
    [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor titleColor], NSForegroundColorAttributeName, [UIFont fontWithName:@"FontNAme" size:titleSize], NSFontAttributeName, nil]];
    
    [[UINavigationBar appearance] setTintColor:[UIColor barColor]];
    
    // Navigation bar buttons appearance
    
    [[UIBarButtonItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor textBarColor], NSForegroundColorAttributeName, shadowColor, NSShadowAttributeName, [UIFont fontWithName:@"FontName" size:titleSize], NSFontAttributeName, nil];
    

    【讨论】:

    • 我可以通过我提到的代码来实现。我的问题是 - 我无法为 Skype 应用和 Inbox UIActivityViewController 上共享活动的应用模式视图设置导航栏颜色和栏按钮颜色
    • 此外,一旦用户选择最近的聊天,Whatsapp 共享活动栏按钮项目的颜色。参考快照
    猜你喜欢
    • 2014-07-30
    • 1970-01-01
    • 2023-03-09
    • 2019-05-12
    • 1970-01-01
    • 2018-07-26
    • 2012-08-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多