Commit aabe9e56 authored by David黄金龙's avatar David黄金龙

添加 渐变函数 UIView UIButton

parent faf2526e
......@@ -9,7 +9,7 @@
import Foundation
import FSPagerView
import Kingfisher
import SwifterSwift
//import SwifterSwift
class YHHomeBannerView: UIView {
......
......@@ -140,7 +140,6 @@ extension YHPersonInformMainViewController {
make.left.right.bottom.equalToSuperview()
}
// homeTableView.backgroundColor = .red//for test hjl
homeTableView.tableHeaderView = myHeadView
......
......@@ -7,7 +7,7 @@
//
import UIKit
import SwifterSwift
//import SwifterSwift
class YHContractMainItemStatusCell: UITableViewCell {
......@@ -60,7 +60,7 @@ class YHContractMainItemStatusCell: UITableViewCell {
let gradientLayer = CAGradientLayer()
gradientLayer.frame = bounds
gradientLayer.colors = [UIColor(red: 0.302, green: 0.624, blue: 0.973, alpha: 1),UIColor(red: 0.231, green: 0.525, blue: 0.969, alpha: 1)].map(\.cgColor)
gradientLayer.colors = UIColor.arrBrandGradaterColors
gradientLayer.locations = [0,1].map { NSNumber(value: $0) }
gradientLayer.startPoint = CGPoint(x: 0.12, y: 0.25)
gradientLayer.endPoint = CGPoint(x: 0.38, y: 0.25)
......
......@@ -42,7 +42,7 @@ class YHInformationFillTipsAlertView: UIView {
tableView.showsHorizontalScrollIndicator = true
tableView.showsVerticalScrollIndicator = false
tableView.rowHeight = UITableView.automaticDimension
// tableView.estimatedRowHeight = 100
// tableView.estimatedRowHeight = 100
tableView.register(YHInformationFillTipsCell.self,forCellReuseIdentifier: YHInformationFillTipsCell.cellReuseIdentifier)
return tableView
}()
......@@ -60,9 +60,9 @@ class YHInformationFillTipsAlertView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = UIColor(white: 0.5, alpha: 0.1)
// let tap = UITapGestureRecognizer(target: self, action: #selector(handleTap))
// tap.delegate = self
// addGestureRecognizer(tap)
// let tap = UITapGestureRecognizer(target: self, action: #selector(handleTap))
// tap.delegate = self
// addGestureRecognizer(tap)
setView()
}
......@@ -72,11 +72,11 @@ class YHInformationFillTipsAlertView: UIView {
}
func setView() {
backgroundColor = UIColor(hex: 0x0000, alpha: 0.5)
backgroundColor = UIColor(hex: 0x000000, alpha: 0.5)
centerView = {
let view = UIView()
view.backgroundColor = .white
view.layer.cornerRadius = 12
view.layer.cornerRadius = 8
return view
}()
addSubview(centerView)
......@@ -96,12 +96,12 @@ class YHInformationFillTipsAlertView: UIView {
}
let checkBtn = UIButton(type: .custom)
checkBtn.setBackgroundImage(UIImage.from(color: UIColor(hex:0x4D9FF8)), for: .normal)
checkBtn.addTarget(self, action: #selector(onClickReadyBtn), for: .touchUpInside)
checkBtn.setTitle("准备完毕", for: .normal)
checkBtn.setTitleColor(.white, for: .normal)
checkBtn.addTarget(self, action: #selector(onClickReadyBtn), for: .touchUpInside)
checkBtn.layer.cornerRadius = 8
checkBtn.clipsToBounds = true
bottomView.addSubview(checkBtn)
checkBtn.snp.makeConstraints { make in
make.bottom.equalToSuperview().offset(-40)
......@@ -109,6 +109,10 @@ class YHInformationFillTipsAlertView: UIView {
make.right.equalTo(-16)
make.height.equalTo(48)
}
checkBtn.layoutIfNeeded()//非常重要!!!!
checkBtn.backgroundGradient()
let lable00 = UILabel(text: "我确认我所提供的材料真实有效,并知悉其中内容。")
lable00.font = kFont(size: 12)
......@@ -262,7 +266,7 @@ extension YHInformationFillTipsAlertView : UITableViewDelegate,UITableViewDataSo
return UIView()
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
......
......@@ -7,6 +7,7 @@
//
import UIKit
import SwifterSwift
extension String {
/// JSONString转换为字典
func toDictionary() -> Dictionary<String, Any> {
......
......@@ -98,5 +98,31 @@ extension UIButton {
return btn
}
}
extension UIButton {
/// 渐变背景
@discardableResult
func backgroundGradient<T: UIButton>() -> T {
let gradientLayer = CAGradientLayer()
//几个颜色
gradientLayer.colors = UIColor.arrBrandGradaterColors.map { $0.cgColor }
//颜色的分界点
gradientLayer.locations = [0, 1.0]
//开始
gradientLayer.startPoint = CGPoint(x: 0.12, y: 0.25)
//结束,主要是控制渐变方向
gradientLayer.endPoint = CGPoint(x: 0.38, y: 0.25)
//多大区域
gradientLayer.frame = bounds
UIGraphicsBeginImageContext(gradientLayer.frame.size)
if let context = UIGraphicsGetCurrentContext() {
gradientLayer.render(in: context)
let outputImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
setBackgroundImage(outputImage, for: .normal)
}
return self as! T
}
}
......@@ -7,7 +7,7 @@
//
import UIKit
import SwifterSwift
//import SwifterSwift
extension UIColor {
......@@ -83,6 +83,5 @@ extension UIColor {
UIGraphicsEndImageContext()
return image!
}
}
......@@ -10,30 +10,30 @@ import UIKit
extension UIFont {
// MARK: - 苹果平方字体
//特细
class func PFSC_Thin(ofSize size : CGFloat = 17) -> UIFont {
class func PFSC_Thin(ofSize size : CGFloat = 15) -> UIFont {
return UIFont(name: "PingFangSC-Thin", size: size)!
}
//细体
class func PFSC_L(ofSize size : CGFloat = 17) -> UIFont {
class func PFSC_L(ofSize size : CGFloat = 15) -> UIFont {
return UIFont(name: "PingFangSC-Light", size: size)!
}
//常规
class func PFSC_R(ofSize size : CGFloat = 17) -> UIFont {
class func PFSC_R(ofSize size : CGFloat = 15) -> UIFont {
return UIFont(name: "PingFangSC-Regular", size: size)!
}
//中等
class func PFSC_M(ofSize size : CGFloat = 17) -> UIFont {
class func PFSC_M(ofSize size : CGFloat = 15) -> UIFont {
return UIFont(name: "PingFangSC-Medium", size: size)!
}
//粗体
static func PFSC_B(ofSize size : CGFloat = 17) -> UIFont {
static func PFSC_B(ofSize size : CGFloat = 15) -> UIFont {
return UIFont(name: "PingFangSC-Semibold", size: size)!
}
//特粗体
static func PFSC_UL(ofSize size : CGFloat = 17) -> UIFont {
static func PFSC_UL(ofSize size : CGFloat = 15) -> UIFont {
return UIFont(name: "PingFangTC-Ultralight", size: size)!
}
......
......@@ -10,23 +10,25 @@ import Foundation
import QuartzCore
extension UIView {
func image(with colors: [Any]) -> UIImage? {
addGradualLayer(colors)
return convertToImage()
}
func addGradualLayer(_ colors: [Any]) {
if colors.count == 0 { return }
//添加银河渐变色 //从左到右
func addYinHeGradualLayer() {
let gradientLayer = CAGradientLayer()
gradientLayer.colors = colors
gradientLayer.colors = UIColor.arrBrandGradaterColors.map(\.cgColor)
gradientLayer.locations = [0, 1.0]
gradientLayer.startPoint = CGPoint(x: 0.12, y: 0.25)
gradientLayer.endPoint = CGPoint(x: 0.38, y: 0.25)
gradientLayer.frame = self.bounds
self.layer.addSublayer(gradientLayer)
gradientLayer.frame = bounds
layer.addSublayer(gradientLayer)
}
func image(with colors: [Any]) -> UIImage? {
addYinHeGradualLayer()
return convertToImage()
}
func convertToImage() -> UIImage? {
let size = self.bounds.size
if size.width <= 0 || size.height <= 0 { return nil }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment