前提・実現したいこと
ContainerView,WKWebViewを使ってサイトを表示しているのですが、そのサイトのヘッダーとstatusBarの色を同じにしたいです
発生している問題・エラーメッセージ
ページの一番上にいるときは色が同じになっているが、下にスクロールすると白になってしまう
該当のソースコード
Swift
1import UIKit 2 3class ReaderFrontEndViewController: UIViewController{ 4 5 @IBOutlet weak var statusBarView: UIView! 6 @IBOutlet weak var appleDevelopReaderView: UIView! 7 8 override func viewDidLoad() { 9 super.viewDidLoad() 10 11 //statusBarviewとappleDevelopReaderViewに少しでも隙間があれば意図した通りになる 12 appleDevelopReaderView.frame = CGRect(x: 0, y: UIApplication.shared.statusBarFrame.height, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height - UIApplication.shared.statusBarFrame.height) 13 14 setStatusBarBackgroundView() 15 } 16 17 private func setStatusBarBackgroundView(){ 18 statusBarView.backgroundColor = UIColor(red: 242/255, green: 242/255, blue: 242/255, alpha: 1.0) 19 statusBarView.frame = (CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width,height:UIApplication.shared.statusBarFrame.height)) 20 view.addSubview(statusBarView) 21 } 22 23}
Swift
1class AppleDeveloperViewController: UIViewController,WKUIDelegate{ 2 3 @IBOutlet weak var webView: WKWebView! 4 5 private var screenSize = CGRect.zero 6 7 override func viewDidLoad() { 8 super.viewDidLoad() 9 10 let myURL = URL(string: "https://developer.apple.com/jp/") 11 let myRequest = URLRequest(url: myURL!) 12 webView.load(myRequest) 13 14 view.addSubview(webView) 15 16 screenSize = UIScreen.main.bounds 17 webView.frame.origin.x = 0 18 webView.frame.origin.y = 0 19 webView.frame.size.height = screenSize.height 20 webView.frame.size.width = screenSize.width 21 } 22} 23 24
試したこと
StatusBarのzPositionを変更する
補足情報(FW/ツールのバージョンなど)
Xcode10.2.1
Swift5.0
よろしくお願いいたします
あなたの回答
tips
プレビュー