3

I have develop a DeviceLayout Library enter link description here

enter image description here

this library provide DeviceLayoutConstraint to set AutoLayout constant per device size

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()
}

per device constant property applied in runtime simulator or device

My question is

Is it possible update rendering using IBInspectable or IBDesignable when select Device?

I want to check rendering in Storyboard or Xib file when device type changed

enter image description here

Cruz
  • 2,602
  • 19
  • 29

1 Answers1

1

Yes, constraints (whether your subclass or the standard constraints) are perfectly compatible with designable views. Clearly, it requires that your @IBDesignable view handles changes in size correctly, but we generally do that.

For example, if you have a designable view that adds a circular shaped CAShapeLayer, you'd add the CAShapeLayer once and only once in the appropriate init methods, but update that layer's path in the layoutSubviews method. For example, see CircleView.

But if you handle size layout changes properly, you automatically handle constraints appropriately, too.

Rob
  • 415,655
  • 72
  • 787
  • 1,044