Commit 044ffc2a authored by David黄金龙's avatar David黄金龙

添加 UIView的扩展

parent 9589b1b9
......@@ -12,6 +12,7 @@
04808C082B4686C10056D53C /* ATAuthSDK_D.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 04808C032B4686510056D53C /* ATAuthSDK_D.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
6203A87EDC96313BBE789D9C /* Pods_galaxy.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 987C69D43AE8D85DC1930DCF /* Pods_galaxy.framework */; };
A51044182B493675006B60BB /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = A51044172B493675006B60BB /* README.md */; };
A510441A2B495DD0006B60BB /* UIView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = A51044192B495DD0006B60BB /* UIView+Extension.swift */; };
A5573ED22B317BFF00D98EC0 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5573ED12B317BFF00D98EC0 /* AppDelegate.swift */; };
A5573EDB2B317C0000D98EC0 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A5573EDA2B317C0000D98EC0 /* Assets.xcassets */; };
A5573EE92B317C0100D98EC0 /* galaxyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5573EE82B317C0100D98EC0 /* galaxyTests.swift */; };
......@@ -109,6 +110,7 @@
58C2405158A4A6632D0E7460 /* Pods-galaxy.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-galaxy.debug.xcconfig"; path = "Target Support Files/Pods-galaxy/Pods-galaxy.debug.xcconfig"; sourceTree = "<group>"; };
987C69D43AE8D85DC1930DCF /* Pods_galaxy.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_galaxy.framework; sourceTree = BUILT_PRODUCTS_DIR; };
A51044172B493675006B60BB /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
A51044192B495DD0006B60BB /* UIView+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+Extension.swift"; sourceTree = "<group>"; };
A5573ECE2B317BFF00D98EC0 /* galaxy.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = galaxy.app; sourceTree = BUILT_PRODUCTS_DIR; };
A5573ED12B317BFF00D98EC0 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
A5573EDA2B317C0000D98EC0 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
......@@ -398,6 +400,7 @@
A5ACE8F72B4564F7002C94D2 /* Extention */ = {
isa = PBXGroup;
children = (
A51044192B495DD0006B60BB /* UIView+Extension.swift */,
A5ACE8F82B4564F7002C94D2 /* UIApplication+Extension.swift */,
A5ACE8F92B4564F7002C94D2 /* UIDevice+Extension.swift */,
A5ACE8FA2B4564F7002C94D2 /* NSAttributedString+Extension.swift */,
......@@ -780,6 +783,7 @@
A5ACE9532B4564F7002C94D2 /* YHBaseViewController.swift in Sources */,
A5ACE9392B4564F7002C94D2 /* UIDevice+Extension.swift in Sources */,
A5ACE9422B4564F7002C94D2 /* AppDelegate+Extension.swift in Sources */,
A510441A2B495DD0006B60BB /* UIView+Extension.swift in Sources */,
A5ACE93E2B4564F7002C94D2 /* UIImage+Extension.swift in Sources */,
A5ACE94C2B4564F7002C94D2 /* BsHUDErrorView.swift in Sources */,
A5D6AB1B2B46A1CC001C10A5 /* YHHomeModel.swift in Sources */,
......
//
// UIView+Extension.swift
// Example
//
// Created by QuintGao on 2022/3/21.
// Copyright © 2022 QuintGao. All rights reserved.
//
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 }
let gradientLayer = CAGradientLayer()
gradientLayer.colors = colors
gradientLayer.locations = [0, 1.0]
gradientLayer.startPoint = CGPoint(x: 0.02, y: 0.5)
gradientLayer.endPoint = CGPoint(x: 1.0, y: 0.5)
gradientLayer.frame = self.bounds
self.layer.addSublayer(gradientLayer)
}
func convertToImage() -> UIImage? {
let size = self.bounds.size
if size.width <= 0 || size.height <= 0 { return nil }
UIGraphicsBeginImageContextWithOptions(size, false, UIScreen.main.scale)
guard let context = UIGraphicsGetCurrentContext() else { return nil }
self.layer.render(in: context)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}
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