2017-04-07 78 views
0

反正是有顯示的背景梯度上的腳本,而不是發射了模擬器的每次看到它的樣子IOS背景漸變 - 故事板

我已經創建並擴展

import UIKit 

extension CAGradientLayer { 

    func stopwatchColour() -> CAGradientLayer { 

     let topColour = UIColor(red: (11/255.0), green: (128/255.0), blue: (105/255.0), alpha: 1) 
     let bottomColour = UIColor(red: (39/255.0), green: (90/255.0), blue: (78/255.0), alpha: 1) 
     let gradientColours: [CGColor] = [topColour.cgColor, bottomColour.cgColor] 
     let gradientLocations: [Float] = [0.0, 1.0] 
     let gradientLayer: CAGradientLayer = CAGradientLayer() 
     gradientLayer.colors = gradientColours 
     gradientLayer.locations = gradientLocations as [NSNumber] 
     return gradientLayer 
    } 
} 

然後從我的控制器

let background = CAGradientLayer().stopwatchColour() 
    background.frame = self.view.bounds 
    self.view.layer.insertSublayer(background, at: 0) 
+2

查找到'IBInspectable'和'IBDesignable' - 你可以創建一個顯示自定義的子類 - 和可編輯 - 在情節提要/界面生成器 – DonMag

回答

0

我建議在快速操場上試試代碼。每當你輸入時,Swift Playground都會執行你的代碼。你可以看到你的背景是什麼樣的,然後根據你的需要進行編輯。然後,您可以將代碼粘貼到Xcode項目中,而無需運行模擬器。

好運