2017-09-11 53 views
0

我想設置我的背景顏色全屏(也包括導航欄和狀態欄)與漸變顏色。現在,我通過創建梯度在導航控制器內的UIViewController中設置背景

func setDefaultColorBackground() { 
    let colorTop = UIColor(hexString: "804b8a").cgColor 
    let colorBottom = UIColor(hexString: "42074b").cgColor 

    let gradientLayer = CAGradientLayer() 
    gradientLayer.colors = [ colorTop, colorBottom] 
    gradientLayer.locations = [ 0.0, 1.0] 
    gradientLayer.frame = self.view.bounds 

    self.view.layer.insertSublayer(gradientLayer, at: 0) 
} 

所以我在ViewController在我view添加層製造這一點。它的工作原理,但它並沒有掩蓋狀態欄和導航欄。看到這個圖像: background

我覺得背景只填充導航欄下的視圖。無論如何,我正在使用.xib並在我的視圖控制器類中手動加載它。

有沒有什麼想法如何做到這一點?非常感謝!

回答

0

我想改變導航欄的顏色,你必須編寫代碼,這也是這樣的:你想提供

UINavigationBar.appearance().barTintColor = UIColor.redColor() 

或任何顏色:

UINavigationBar.appearance().barTintColor = UIColor(red: 0, green: 0/255, blue: 205/255, alpha: 1) 
UINavigationBar.appearance().tintColor = UIColor.whiteColor() 
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()] 

我希望對你有所幫助。快樂編碼:)

相關問題