Skip to content

Commit

Permalink
[RTCCommon] update 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
abyyxwang committed Nov 12, 2024
1 parent 32d0af5 commit e9f2d28
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 274 deletions.
128 changes: 64 additions & 64 deletions Sources/RTCCommon/Extension/CGFloat+scale375.swift
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()
}
}
130 changes: 65 additions & 65 deletions Sources/RTCCommon/Extension/UIView+roundrect.swift
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
}
}
Loading

0 comments on commit e9f2d28

Please sign in to comment.