我已经开发了一个DeviceLayout
库在此处输入链接描述
该库提供DeviceLayoutConstraint
根据设备大小设置 AutoLayout 常量
import UIKit
import Device
class DeviceLayoutConstraint: NSLayoutConstraint {
@IBInspectable var inch3_5: CGFloat = 0.0 { didSet { updateConstant(size: .screen3_5Inch, constant: inch3_5)}}
@IBInspectable var inch4: CGFloat = 0.0 { didSet { updateConstant(size: .screen4Inch, constant: inch4)}}
@IBInspectable var inch4_7: CGFloat = 0.0 { didSet { updateConstant(size: .screen4_7Inch, constant: inch4_7)}}
@IBInspectable var inch5_5: CGFloat = 0.0 { didSet { updateConstant(size: .screen5_5Inch, constant: inch5_5)}}
@IBInspectable var inch7_9: CGFloat = 0.0 { didSet { updateConstant(size: .screen7_9Inch, constant: inch7_9)}}
@IBInspectable var inch9_7: CGFloat = 0.0 { didSet { updateConstant(size: .screen9_7Inch, constant: inch9_7)}}
@IBInspectable var inch12_9: CGFloat = 0.0 { didSet { updateConstant(size: .screen12_9Inch, constant: inch12_9)}}
fileprivate func updateConstant(size: Size, constant: CGFloat) {
if size == deviceSize() {
self.constant = constant
layoutIfNeeded()
}
}
open func deviceSize() -> Size {
return Device.deviceSize
}
open func layoutIfNeeded() {
self.firstItem.layoutIfNeeded()
self.secondItem?.layoutIfNeeded()
}
}
fileprivate extension Device {
static let deviceSize = Device.size()
}
在运行时模拟器或设备中应用的每个设备常量属性
我的问题是
选择设备时是否可以使用 IBInspectable 或 IBDesignable 更新渲染?
我想在设备类型更改时检查 Storyboard 或 Xib 文件中的渲染