-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
abyyxwang
committed
Nov 12, 2024
1 parent
32d0af5
commit e9f2d28
Showing
3 changed files
with
274 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,67 @@ | ||
//// | ||
//// CGFloat+scale375.swift | ||
//// RTCCommon | ||
//// | ||
//// Created by krabyu on 2023/10/16. | ||
//// Copyright © 2023 Tencent. All rights reserved. | ||
//// | ||
// | ||
//import Foundation | ||
//import UIKit | ||
// CGFloat+scale375.swift | ||
// RTCCommon | ||
// | ||
//public let screenWidth = min(UIScreen.main.bounds.width, UIScreen.main.bounds.height) | ||
//public let screenHeight = max(UIScreen.main.bounds.width,UIScreen.main.bounds.height) | ||
// Created by krabyu on 2023/10/16. | ||
// Copyright © 2023 Tencent. All rights reserved. | ||
// | ||
//public let deviceIsiPhoneX : Bool = { | ||
// if UIDevice.current.userInterfaceIdiom == .pad { | ||
// return false | ||
// } | ||
// let size = UIScreen.main.bounds.size | ||
// let notchValue = Int(size.width/size.height*100) | ||
// if notchValue == 216 || notchValue == 46 { | ||
// return true | ||
// } | ||
// return false | ||
//}() | ||
// | ||
//public let deviceSafeBottomHeight : CGFloat = { | ||
// if deviceIsiPhoneX { | ||
// return 34 | ||
// } | ||
// else { | ||
// return 0 | ||
// } | ||
//}() | ||
// | ||
//extension CGFloat { | ||
// | ||
// /// 375设计图中的尺寸 | ||
// /// | ||
// /// - Returns: 最终结果缩放结果 | ||
// public func scale375Width(exceptPad: Bool = true) -> CGFloat { | ||
// if UIDevice.current.userInterfaceIdiom == .pad { | ||
// return exceptPad ? self * 1.5 : self * (screenWidth / 375.00) | ||
// } | ||
// return self * (screenWidth / 375.00) | ||
// } | ||
// | ||
// public func scale375Height(exceptPad: Bool = true) -> CGFloat { | ||
// if UIDevice.current.userInterfaceIdiom == .pad { | ||
// return exceptPad ? self * 1.5 : self * (screenHeight / 812.00) | ||
// } | ||
// return self * (screenHeight / 812.00) | ||
// } | ||
//} | ||
// | ||
//extension Int { | ||
// /// 375设计图中的尺寸 | ||
// /// | ||
// /// - Returns: 最终结果缩放结果 | ||
// public func scale375Width(exceptPad: Bool = true) -> CGFloat { | ||
// return CGFloat(self).scale375Width() | ||
// } | ||
// | ||
// public func scale375Height(exceptPad: Bool = true) -> CGFloat { | ||
// return CGFloat(self).scale375Height() | ||
// } | ||
//} | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
public let screenWidth = min(UIScreen.main.bounds.width, UIScreen.main.bounds.height) | ||
public let screenHeight = max(UIScreen.main.bounds.width,UIScreen.main.bounds.height) | ||
|
||
public let deviceIsiPhoneX : Bool = { | ||
if UIDevice.current.userInterfaceIdiom == .pad { | ||
return false | ||
} | ||
let size = UIScreen.main.bounds.size | ||
let notchValue = Int(size.width/size.height*100) | ||
if notchValue == 216 || notchValue == 46 { | ||
return true | ||
} | ||
return false | ||
}() | ||
|
||
public let deviceSafeBottomHeight : CGFloat = { | ||
if deviceIsiPhoneX { | ||
return 34 | ||
} | ||
else { | ||
return 0 | ||
} | ||
}() | ||
|
||
extension CGFloat { | ||
|
||
/// 375设计图中的尺寸 | ||
/// | ||
/// - Returns: 最终结果缩放结果 | ||
public func scale375Width(exceptPad: Bool = true) -> CGFloat { | ||
if UIDevice.current.userInterfaceIdiom == .pad { | ||
return exceptPad ? self * 1.5 : self * (screenWidth / 375.00) | ||
} | ||
return self * (screenWidth / 375.00) | ||
} | ||
|
||
public func scale375Height(exceptPad: Bool = true) -> CGFloat { | ||
if UIDevice.current.userInterfaceIdiom == .pad { | ||
return exceptPad ? self * 1.5 : self * (screenHeight / 812.00) | ||
} | ||
return self * (screenHeight / 812.00) | ||
} | ||
} | ||
|
||
extension Int { | ||
/// 375设计图中的尺寸 | ||
/// | ||
/// - Returns: 最终结果缩放结果 | ||
public func scale375Width(exceptPad: Bool = true) -> CGFloat { | ||
return CGFloat(self).scale375Width() | ||
} | ||
|
||
public func scale375Height(exceptPad: Bool = true) -> CGFloat { | ||
return CGFloat(self).scale375Height() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,67 @@ | ||
//// | ||
//// UIView+roundrect.swift | ||
//// TRTCScene | ||
//// | ||
//// Created by adams on 2021/4/8. | ||
//// Copyright © 2022 Tencent. All rights reserved. | ||
// | ||
//import Foundation | ||
//import UIKit | ||
// UIView+roundrect.swift | ||
// TRTCScene | ||
// | ||
//public extension UIView { | ||
// func roundedRect(rect: CGRect, byRoundingCorners: UIRectCorner, cornerRadii: CGSize) { | ||
// let maskPath = UIBezierPath(roundedRect: rect, byRoundingCorners: byRoundingCorners, cornerRadii: cornerRadii) | ||
// let maskLayer = CAShapeLayer() | ||
// maskLayer.frame = bounds | ||
// maskLayer.path = maskPath.cgPath | ||
// layer.mask = maskLayer | ||
// } | ||
// | ||
// func roundedCircle(rect: CGRect) { | ||
// roundedRect(rect: rect, byRoundingCorners: .allCorners, cornerRadii: CGSize(width: bounds.size.width / 2, height: bounds.size.height / 2)) | ||
// } | ||
// | ||
// func clearRoundedCorners() { | ||
// layer.mask = nil | ||
// } | ||
//} | ||
// | ||
//public extension UIView { | ||
// private struct AssociatedKeys { | ||
// static var gradientLayerKey = "gradientLayerKey" | ||
// } | ||
// | ||
// var gradientLayer: CAGradientLayer? { | ||
// get { | ||
// return objc_getAssociatedObject(self, &AssociatedKeys.gradientLayerKey) as? CAGradientLayer | ||
// } | ||
// set { | ||
// objc_setAssociatedObject(self, &AssociatedKeys.gradientLayerKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) | ||
// } | ||
// } | ||
// | ||
// func removeGradientLayer() { | ||
// guard let glayer = gradientLayer else { | ||
// return | ||
// } | ||
// glayer.removeFromSuperlayer() | ||
// gradientLayer = nil | ||
// } | ||
// | ||
// @discardableResult | ||
// func gradient(colors: [UIColor], bounds: CGRect = .zero, isVertical: Bool = false) -> CAGradientLayer { | ||
// let gradientLayer = self.gradientLayer ?? CAGradientLayer() | ||
// if isVertical { | ||
// gradientLayer.startPoint = CGPoint(x: 0.5, y: 0.0) | ||
// gradientLayer.endPoint = CGPoint(x: 0.5, y: 1.0) | ||
// } else { | ||
// gradientLayer.startPoint = CGPoint(x: 0.0, y: 0.5) | ||
// gradientLayer.endPoint = CGPoint(x: 1.0, y: 0.5) | ||
// } | ||
// self.gradientLayer = gradientLayer | ||
// gradientLayer.colors = colors.map { $0.cgColor } | ||
// gradientLayer.frame = bounds == .zero ? self.bounds : bounds | ||
// layer.insertSublayer(gradientLayer, at: 0) | ||
// return gradientLayer | ||
// } | ||
//} | ||
// Created by adams on 2021/4/8. | ||
// Copyright © 2022 Tencent. All rights reserved. | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
public extension UIView { | ||
func roundedRect(rect: CGRect, byRoundingCorners: UIRectCorner, cornerRadii: CGSize) { | ||
let maskPath = UIBezierPath(roundedRect: rect, byRoundingCorners: byRoundingCorners, cornerRadii: cornerRadii) | ||
let maskLayer = CAShapeLayer() | ||
maskLayer.frame = bounds | ||
maskLayer.path = maskPath.cgPath | ||
layer.mask = maskLayer | ||
} | ||
|
||
func roundedCircle(rect: CGRect) { | ||
roundedRect(rect: rect, byRoundingCorners: .allCorners, cornerRadii: CGSize(width: bounds.size.width / 2, height: bounds.size.height / 2)) | ||
} | ||
|
||
func clearRoundedCorners() { | ||
layer.mask = nil | ||
} | ||
} | ||
|
||
public extension UIView { | ||
private struct AssociatedKeys { | ||
static var gradientLayerKey = "gradientLayerKey" | ||
} | ||
|
||
var gradientLayer: CAGradientLayer? { | ||
get { | ||
return objc_getAssociatedObject(self, &AssociatedKeys.gradientLayerKey) as? CAGradientLayer | ||
} | ||
set { | ||
objc_setAssociatedObject(self, &AssociatedKeys.gradientLayerKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) | ||
} | ||
} | ||
|
||
func removeGradientLayer() { | ||
guard let glayer = gradientLayer else { | ||
return | ||
} | ||
glayer.removeFromSuperlayer() | ||
gradientLayer = nil | ||
} | ||
|
||
@discardableResult | ||
func gradient(colors: [UIColor], bounds: CGRect = .zero, isVertical: Bool = false) -> CAGradientLayer { | ||
let gradientLayer = self.gradientLayer ?? CAGradientLayer() | ||
if isVertical { | ||
gradientLayer.startPoint = CGPoint(x: 0.5, y: 0.0) | ||
gradientLayer.endPoint = CGPoint(x: 0.5, y: 1.0) | ||
} else { | ||
gradientLayer.startPoint = CGPoint(x: 0.0, y: 0.5) | ||
gradientLayer.endPoint = CGPoint(x: 1.0, y: 0.5) | ||
} | ||
self.gradientLayer = gradientLayer | ||
gradientLayer.colors = colors.map { $0.cgColor } | ||
gradientLayer.frame = bounds == .zero ? self.bounds : bounds | ||
layer.insertSublayer(gradientLayer, at: 0) | ||
return gradientLayer | ||
} | ||
} |
Oops, something went wrong.