// // 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 } } }