0
点赞
收藏
分享

微信扫一扫

044_swift_批量设置渐变背景

成义随笔 2023-03-10 阅读 132


效果

可以在Base类中添加

//
// BaseViewController.swift
// videowallpaper
//
// Created by liuan on 2020/6/11.
// Copyright © 2020 liuan. All rights reserved.
//

import UIKit

class BaseViewController: UIViewController {
var width40 : Int = 0
var widthFull : Int = 0
var heightFull : Int = 0
override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
initUI()
}

func initUI(){

self.width40 = Int(self.view.frame.size.width) - 40
self.heightFull = Int(self.view.frame.size.height)
self.widthFull = Int(self.view.frame.size.width)

let gradientLayer = CAGradientLayer()
gradientLayer.bounds = CGRect(x: 0, y: 0, width: self.widthFull+1, height: self.heightFull+1)
gradientLayer.position = CGPoint(x: self.widthFull/2, y: self.heightFull/2)
gradientLayer.colors = [UIColor(red: 48.0/255, green: 35.0/255, blue: 174.0/255, alpha: 1.0).cgColor, UIColor(red: 126.0/255, green: 67.0/255, blue: 170.0/255, alpha: 1.0).cgColor]

gradientLayer.startPoint = CGPoint(x: 1, y: 1)
gradientLayer.endPoint = CGPoint(x: 0, y: 0)
self.view.layer.insertSublayer(gradientLayer, at: 0)
}
/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/

}

 

举报

相关推荐

0 条评论