如何更改导航栏和barbuttonitem颜色& UIActivityViewController中Modal视图的字体?

时间:2016-03-22 07:07:27

标签: ios uinavigationcontroller uinavigationbar uibarbuttonitem uiactivityviewcontroller

我已将状态栏设置为指向内容,方法是将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
  2. 上的Skype,收件箱(Gmail邮件应用)
  3. 无法设置barButtonItem,例如“取消”字体&使用UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UINavigationBar.self]).setTitleTextAttributes([NSFontAttributeName : UIFont.systemFontOfSize(16.0, weight: UIFontWeightThin)], forState: UIControlState.Normal)
  4. 的大小

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

    1. 当我从最近聊天中选择whatsapp共享活动的聊天时,barbuttonitem颜色变为默认蓝色 - See Snapshot enter image description here

    2. 最重要的是,我使用的解决方案支持iOS 8.0,8.2或更高版本。我希望从7.0或7.1开始的版本实现所有相同的功能。我该怎么办?

1 个答案:

答案 0 :(得分:0)

// 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];