プログラムでUIViewにグラデーションを追加しようとしていますが、動作しません。色が全くないように見えます。関連するコードとスクリーンショットを添付しました。私がグラデーションを適用している下の正方形に注目してください。誰かが私がここで間違っていることを理解するのを助けることができますか?UIViewにグラデーションを適用しないでください
let sundayView = UIView()
override func viewDidLoad() {
super.viewDidLoad()
setupViews()
setupSundayView()
}
func setupViews() {
sundayView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(sundayView)
}
func setupSundayView() {
sundayView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activateConstraints([
sundayView.centerXAnchor.constraintEqualToAnchor(view.centerXAnchor),
sundayView.topAnchor.constraintEqualToAnchor(fridayView.bottomAnchor, constant: 16.0),
sundayView.trailingAnchor.constraintEqualToAnchor(view.trailingAnchor, constant: -8.0),
sundayView.heightAnchor.constraintEqualToAnchor(mondayView.heightAnchor),
sundayView.widthAnchor.constraintEqualToAnchor(mondayView.widthAnchor)
])
let gradient = CAGradientLayer()
gradient.frame = sundayView.bounds
gradient.colors = [
UIColor(red:1.00, green:0.37, blue:0.23, alpha:1.0).CGColor,
UIColor(red:1.00, green:0.16, blue:0.41, alpha:1.0).CGColor
]
sundayView.layer.insertSublayer(gradient, atIndex: 0)
}
はあなたではないでした'QuartzCore'フレームワークをインポートするのを忘れましたか? –
私はその必要はないと思います。私はスーパービューにグラデーションを適用しようとしました。それはインポートすることなく働いた。 –