Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Xcode和Swift创建的iOS应用程序中状态栏的自定义背景色_Ios_Iphone_Xcode_Statusbar_Uistatusbar - Fatal编程技术网

使用Xcode和Swift创建的iOS应用程序中状态栏的自定义背景色

使用Xcode和Swift创建的iOS应用程序中状态栏的自定义背景色,ios,iphone,xcode,statusbar,uistatusbar,Ios,Iphone,Xcode,Statusbar,Uistatusbar,我已经用谷歌搜索了一点,但没有成功。 我希望在所有ViewController中为状态栏设置自定义背景色(仅在纵向模式下)。ViewController由TabBarController管理 有人知道怎么做吗?也许有人有代码示例吗?试试这个,它会有帮助 let demoView = UIView() demoView.frame = CGRectMake(0, 0, 320, 22) demoView.backgroundColor = UIColor.redColor() self.view.

我已经用谷歌搜索了一点,但没有成功。 我希望在所有ViewController中为状态栏设置自定义背景色(仅在纵向模式下)。ViewController由TabBarController管理


有人知道怎么做吗?也许有人有代码示例吗?

试试这个,它会有帮助

let demoView = UIView()
demoView.frame = CGRectMake(0, 0, 320, 22)
demoView.backgroundColor = UIColor.redColor()
self.view.addSubview(demoView)

我已经通过在状态栏下方放置UIView并设置背景色解决了这个问题。但我必须清除所有约束并再次添加它们,以使UIView隐藏在横向模式下。

请参考此链接,它可能会对您有所帮助,以下是解决方案:我将其放在AppDelegate.swift中的didfishlaunchingwithoptions中,对吗?我得到:类型为“AppDelegate”的值没有成员“view”。这是什么意思?将它放在视图控制器的viewDidLoad()中。这就是我得到的:似乎有问题。使用self.view.frame.size.width代替320