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

添加 渐变函数 UIView UIButton

parent faf2526e
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
import Foundation import Foundation
import FSPagerView import FSPagerView
import Kingfisher import Kingfisher
import SwifterSwift //import SwifterSwift
class YHHomeBannerView: UIView { class YHHomeBannerView: UIView {
......
...@@ -140,7 +140,6 @@ extension YHPersonInformMainViewController { ...@@ -140,7 +140,6 @@ extension YHPersonInformMainViewController {
make.left.right.bottom.equalToSuperview() make.left.right.bottom.equalToSuperview()
} }
// homeTableView.backgroundColor = .red//for test hjl
homeTableView.tableHeaderView = myHeadView homeTableView.tableHeaderView = myHeadView
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
// //
import UIKit import UIKit
import SwifterSwift //import SwifterSwift
class YHContractMainItemStatusCell: UITableViewCell { class YHContractMainItemStatusCell: UITableViewCell {
...@@ -60,7 +60,7 @@ class YHContractMainItemStatusCell: UITableViewCell { ...@@ -60,7 +60,7 @@ class YHContractMainItemStatusCell: UITableViewCell {
let gradientLayer = CAGradientLayer() let gradientLayer = CAGradientLayer()
gradientLayer.frame = bounds 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.locations = [0,1].map { NSNumber(value: $0) }
gradientLayer.startPoint = CGPoint(x: 0.12, y: 0.25) gradientLayer.startPoint = CGPoint(x: 0.12, y: 0.25)
gradientLayer.endPoint = CGPoint(x: 0.38, y: 0.25) gradientLayer.endPoint = CGPoint(x: 0.38, y: 0.25)
......
...@@ -42,7 +42,7 @@ class YHInformationFillTipsAlertView: UIView { ...@@ -42,7 +42,7 @@ class YHInformationFillTipsAlertView: UIView {
tableView.showsHorizontalScrollIndicator = true tableView.showsHorizontalScrollIndicator = true
tableView.showsVerticalScrollIndicator = false tableView.showsVerticalScrollIndicator = false
tableView.rowHeight = UITableView.automaticDimension tableView.rowHeight = UITableView.automaticDimension
// tableView.estimatedRowHeight = 100 // tableView.estimatedRowHeight = 100
tableView.register(YHInformationFillTipsCell.self,forCellReuseIdentifier: YHInformationFillTipsCell.cellReuseIdentifier) tableView.register(YHInformationFillTipsCell.self,forCellReuseIdentifier: YHInformationFillTipsCell.cellReuseIdentifier)
return tableView return tableView
}() }()
...@@ -60,9 +60,9 @@ class YHInformationFillTipsAlertView: UIView { ...@@ -60,9 +60,9 @@ class YHInformationFillTipsAlertView: UIView {
override init(frame: CGRect) { override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
backgroundColor = UIColor(white: 0.5, alpha: 0.1) backgroundColor = UIColor(white: 0.5, alpha: 0.1)
// let tap = UITapGestureRecognizer(target: self, action: #selector(handleTap)) // let tap = UITapGestureRecognizer(target: self, action: #selector(handleTap))
// tap.delegate = self // tap.delegate = self
// addGestureRecognizer(tap) // addGestureRecognizer(tap)
setView() setView()
} }
...@@ -72,11 +72,11 @@ class YHInformationFillTipsAlertView: UIView { ...@@ -72,11 +72,11 @@ class YHInformationFillTipsAlertView: UIView {
} }
func setView() { func setView() {
backgroundColor = UIColor(hex: 0x0000, alpha: 0.5) backgroundColor = UIColor(hex: 0x000000, alpha: 0.5)
centerView = { centerView = {
let view = UIView() let view = UIView()
view.backgroundColor = .white view.backgroundColor = .white
view.layer.cornerRadius = 12 view.layer.cornerRadius = 8
return view return view
}() }()
addSubview(centerView) addSubview(centerView)
...@@ -96,12 +96,12 @@ class YHInformationFillTipsAlertView: UIView { ...@@ -96,12 +96,12 @@ class YHInformationFillTipsAlertView: UIView {
} }
let checkBtn = UIButton(type: .custom) 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.setTitle("准备完毕", for: .normal)
checkBtn.setTitleColor(.white, for: .normal) checkBtn.setTitleColor(.white, for: .normal)
checkBtn.addTarget(self, action: #selector(onClickReadyBtn), for: .touchUpInside)
checkBtn.layer.cornerRadius = 8 checkBtn.layer.cornerRadius = 8
checkBtn.clipsToBounds = true checkBtn.clipsToBounds = true
bottomView.addSubview(checkBtn) bottomView.addSubview(checkBtn)
checkBtn.snp.makeConstraints { make in checkBtn.snp.makeConstraints { make in
make.bottom.equalToSuperview().offset(-40) make.bottom.equalToSuperview().offset(-40)
...@@ -109,6 +109,10 @@ class YHInformationFillTipsAlertView: UIView { ...@@ -109,6 +109,10 @@ class YHInformationFillTipsAlertView: UIView {
make.right.equalTo(-16) make.right.equalTo(-16)
make.height.equalTo(48) make.height.equalTo(48)
} }
checkBtn.layoutIfNeeded()//非常重要!!!!
checkBtn.backgroundGradient()
let lable00 = UILabel(text: "我确认我所提供的材料真实有效,并知悉其中内容。") let lable00 = UILabel(text: "我确认我所提供的材料真实有效,并知悉其中内容。")
lable00.font = kFont(size: 12) lable00.font = kFont(size: 12)
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
// //
import UIKit import UIKit
import SwifterSwift
extension String { extension String {
/// JSONString转换为字典 /// JSONString转换为字典
func toDictionary() -> Dictionary<String, Any> { func toDictionary() -> Dictionary<String, Any> {
......
...@@ -98,5 +98,31 @@ extension UIButton { ...@@ -98,5 +98,31 @@ extension UIButton {
return btn 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 @@ ...@@ -7,7 +7,7 @@
// //
import UIKit import UIKit
import SwifterSwift //import SwifterSwift
extension UIColor { extension UIColor {
...@@ -83,6 +83,5 @@ extension UIColor { ...@@ -83,6 +83,5 @@ extension UIColor {
UIGraphicsEndImageContext() UIGraphicsEndImageContext()
return image! return image!
} }
} }
...@@ -10,30 +10,30 @@ import UIKit ...@@ -10,30 +10,30 @@ import UIKit
extension UIFont { extension UIFont {
// MARK: - 苹果平方字体 // 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)! 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)! 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)! 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)! 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)! 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)! return UIFont(name: "PingFangTC-Ultralight", size: size)!
} }
......
...@@ -10,23 +10,25 @@ import Foundation ...@@ -10,23 +10,25 @@ import Foundation
import QuartzCore import QuartzCore
extension UIView { 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() let gradientLayer = CAGradientLayer()
gradientLayer.colors = colors gradientLayer.colors = UIColor.arrBrandGradaterColors.map(\.cgColor)
gradientLayer.locations = [0, 1.0] gradientLayer.locations = [0, 1.0]
gradientLayer.startPoint = CGPoint(x: 0.12, y: 0.25) gradientLayer.startPoint = CGPoint(x: 0.12, y: 0.25)
gradientLayer.endPoint = CGPoint(x: 0.38, y: 0.25) gradientLayer.endPoint = CGPoint(x: 0.38, y: 0.25)
gradientLayer.frame = self.bounds gradientLayer.frame = bounds
self.layer.addSublayer(gradientLayer) layer.addSublayer(gradientLayer)
}
func image(with colors: [Any]) -> UIImage? {
addYinHeGradualLayer()
return convertToImage()
} }
func convertToImage() -> UIImage? { func convertToImage() -> UIImage? {
let size = self.bounds.size let size = self.bounds.size
if size.width <= 0 || size.height <= 0 { return nil } 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