Engineering

Get margin between UIView to target UIView

extension UIView {

  // The margin between self to target view
  public func margin(to: UICoordinateSpace) -> UIEdgeInsets {

    let frame = convert(bounds, to: to)

    return UIEdgeInsets(
      top: frame.minY,
      left: frame.minX,
      bottom: to.bounds.height - frame.maxY,
      right: to.bounds.width - frame.maxX
    )
  }
}