如何使用Swift

时间:2015-06-22 03:33:46

标签: swift ios8

我正在尝试更改状态栏中的文字颜色以匹配其余的应用外观。我可以很容易地在导航栏中为MFMailComposeViewController更改文本颜色:

myEmailComposerViewConotroller.navigationBar.tintColor = UIColor.whiteColor()

在更改状态栏的文本颜色时,我是否遗漏了API中的内容?

2 个答案:

答案 0 :(得分:0)

根据我对你的问题的理解,我认为你会想做这样的事情:

myEmailComposerViewConotroller.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()]

titleTextAttributes的类型为[NSObject: AnyObject]?

因此我们将其初始化为:

[NSForegroundColorAttributeName : UIColor.whiteColor()]

答案 1 :(得分:0)

我已经回答过类似的问题:how to change statusbar color in one view controller using swift?

将project.plist中的View controller-based status bar appearance设置为

MFMailViewController进行子类化并实施自定义viewWillAppearviewWillDisappear函数

使用viewWillAppearviewWillDisappear设置和重置statusBarStyle,同时保留一个属性与之前的statusBarStyle一样

let initialStatusBarStyle : UIStatusBarStyle

func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    initialStatusBarStyle = UIApplication.sharedApplication().statusBarStyle
    UIApplication.sharedApplication().setStatusBarStyle(.LightContent, animated: animated)
}

func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)
    UIApplication.sharedApplication().setStatusBarStyle(initialStatusBarStyle, animated: animated)
}