Skip to content

Commit

Permalink
Copy constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
Domas Nutautas committed May 15, 2020
1 parent 0acc261 commit da9e839
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Sources/NibLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public struct IBNibLoader<NibLoadableView: NibLoadable> where NibLoadableView: U

let nibView = type(of: view).fromNib()
copyProperties(to: nibView)
copyConstraints(to: nibView)

return nibView
}
Expand Down Expand Up @@ -71,6 +72,20 @@ public struct IBNibLoader<NibLoadableView: NibLoadable> where NibLoadableView: U
nibView.isHidden = view.isHidden
}

private func copyConstraints(to nibView: UIView) {
nibView.addConstraints(
view.constraints.map {
NSLayoutConstraint(
item: $0.firstItem === view ? nibView : $0.firstItem as Any,
attribute: $0.firstAttribute,
relatedBy: $0.relation,
toItem: $0.secondItem === view ? nibView : $0.secondItem,
attribute: $0.secondAttribute,
multiplier: $0.multiplier,
constant: $0.constant)
}
)
}
}


Expand Down

0 comments on commit da9e839

Please sign in to comment.