54709
```

    override func viewDidLoad() {
        super.viewDidLoad()
    
        //グラデーションの開始色
        let topColor = UIColor(red:147, green:6, blue:229, alpha:1)
        //グラデーションの開始色
        let bottomColor = UIColor(red:23, green:232, blue:252, alpha:1)
    
        let gradientLayer = CAGradientLayer()
        gradientLayer.frame = view.frame
        gradientLayer.colors = [topColor.cgColor, bottomColor.cgColor]
        gradientLayer.locations = [0.0, 1.0]
        gradientLayer.startPoint = CGPoint(x: 0.0, y: 1.0)
        gradientLayer.endPoint = CGPoint(x: 1.0, y: 1.0)
        gradientLayer.cornerRadius = 20.0
    
        self.view.layer.insertSublayer(gradientLayer, at: 0)
    
    }
    
```

[![画像の説明をここに入力](https://i.stack.imgur.com/S1cDJ.png)](https://i.stack.imgur.com/S1cDJ.png)  
[![view](https://i.stack.imgur.com/pFo2f.png)](https://i.stack.imgur.com/pFo2f.png)
CC BY-SA 4.0
2019-05-04T01:50:57.447
54702
2019-05-04T09:06:59.047
34162
question
swift xcode
viewの背景がグラデーションせず真っ白になる
UIColorの書き方を間違えてた。  
全然違う箇所だと思ってたわ。

```

    //グラデーションの開始色
    let topColor = UIColor(displayP3Red: 147/255, green: 6/255, blue: 229/255, alpha: 1.0)
    //グラデーションの開始色
    let bottomColor = UIColor(displayP3Red: 23/255, green: 232/255, blue: 252/255, alpha: 1.0)
    
```
CC BY-SA 4.0
2019-05-04T09:06:59.047
54709
2019-05-04T09:06:59.047
34162
54702
answer