Music_Player3/relax.offline.mp3.music/MP/Common/Extension(扩展)/LayoutConstraint.swift
2024-07-05 17:25:49 +08:00

111 lines
3.0 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// LayoutConstraint.swift
// MusicPlayer
//
// Created by Mr.Zhou on 2024/3/27.
//
import UIKit
import Foundation
//SnapKit
@_exported import SnapKit
//MARK: -
extension NSLayoutConstraint {
///
@IBInspectable var adapterScreen: Bool {
get {
return true
}
set {
if newValue {
self.constant = self.constant * width
}
}
}
///
/// - Parameter multiplier:
/// - Returns:
func setMultiplier(multiplier:CGFloat) -> NSLayoutConstraint {
NSLayoutConstraint.deactivate([self])
let newConstraint = NSLayoutConstraint(
item: firstItem as Any,
attribute: firstAttribute,
relatedBy: relation,
toItem: secondItem,
attribute: secondAttribute,
multiplier: multiplier,
constant: constant)
newConstraint.priority = priority
newConstraint.shouldBeArchived = self.shouldBeArchived
newConstraint.identifier = self.identifier
NSLayoutConstraint.activate([newConstraint])
return newConstraint
}
}
//MARK: - CALayer
extension CALayer {
///线
var borderUIColor: UIColor {
get {
return UIColor(cgColor: self.borderColor!)
} set {
self.borderColor = newValue.cgColor
}
}
}
//MARK: - UIView
extension UIView {
///
@IBInspectable var cornerRadius: CGFloat {
get {
return layer.cornerRadius
} set {
layer.masksToBounds = (newValue > 0)
layer.cornerRadius = newValue * width
}
}
///线
@IBInspectable var borderWidth: CGFloat {
get {
return layer.borderWidth
} set {
layer.borderWidth = newValue
}
}
///线
@IBInspectable var borderColor: UIColor {
get {
return layer.borderUIColor
} set {
layer.borderColor = newValue.cgColor
}
}
///
func parentController() -> UIViewController? {
var responder = self.next;
repeat {
if(responder?.isKind(of:UIViewController.classForCoder()))!{
return responder as? UIViewController
}
responder = responder?.next
}
while((responder) != nil)
return nil;
}
///
/// - Parameter ofType:
/// - Returns: nil
func parentController<T: UIViewController>(ofType: T.Type) -> T? {
var responder = self.next
while let nextResponder = responder {
if let viewController = nextResponder as? T {
return viewController
}
responder = nextResponder.next
}
return nil
}
}