Skip to content

Commit

Permalink
Update UIView+Pin.swift to force auto layout using `translatesAutor…
Browse files Browse the repository at this point in the history
…esizingMaskIntoConstraints`
  • Loading branch information
mpintoQoQa committed Nov 8, 2021
1 parent 4af8b77 commit e760ae1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.0.10] - 2021-11-08

### Updated
- Update `UIView+Pin.swift` to force auto layout using `translatesAutoresizingMaskIntoConstraints`

## [0.0.9] - 2021-09-09

### Added
Expand Down
5 changes: 5 additions & 0 deletions Sources/Qit/Extensions/UIKit/UIView/UIView+Pin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extension UIView {
@discardableResult public func pinToSuperviewEdges(
margins: UIEdgeInsets = UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: 0.0)) -> [NSLayoutConstraint] {
guard let superview = superview else { return [NSLayoutConstraint]() }
self.translatesAutoresizingMaskIntoConstraints = false
let topConstraint = topAnchor.constraint(equalTo: superview.topAnchor, constant: margins.top)
let leftConstraint = leftAnchor.constraint(equalTo: superview.leftAnchor, constant: margins.left)
let bottomConstraint = bottomAnchor.constraint(equalTo: superview.bottomAnchor, constant: -margins.bottom)
Expand Down Expand Up @@ -62,6 +63,7 @@ extension UIView {
/// - Parameter view: UIView that will be constrained with
/// - Returns: The created constraint
@discardableResult public func pinRightToView(_ view: UIView, margin: CGFloat = 0.0) -> NSLayoutConstraint {
self.translatesAutoresizingMaskIntoConstraints = false
let constraint = rightAnchor.constraint(equalTo: view.rightAnchor, constant: -margin)
constraint.isActive = true
return constraint
Expand All @@ -72,6 +74,7 @@ extension UIView {
/// - Parameter view: UIView that will be constrained with
/// - Returns: The created constraint
@discardableResult public func pinLeftToView(_ view: UIView, margin: CGFloat = 0.0) -> NSLayoutConstraint {
self.translatesAutoresizingMaskIntoConstraints = false
let constraint = leftAnchor.constraint(equalTo: view.leftAnchor, constant: margin)
constraint.isActive = true
return constraint
Expand All @@ -82,6 +85,7 @@ extension UIView {
/// - Parameter view: UIView that will be constrained with
/// - Returns: The created constraint
@discardableResult public func pinTopToView(_ view: UIView, margin: CGFloat = 0.0) -> NSLayoutConstraint {
self.translatesAutoresizingMaskIntoConstraints = false
let constraint = topAnchor.constraint(equalTo: view.topAnchor, constant: margin)
constraint.isActive = true
return constraint
Expand All @@ -92,6 +96,7 @@ extension UIView {
/// - Parameter view: UIView that will be constrained with
/// - Returns: The created constraint
@discardableResult public func pinBottomToView(_ view: UIView, margin: CGFloat = 0.0) -> NSLayoutConstraint {
self.translatesAutoresizingMaskIntoConstraints = false
let constraint = bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -margin)
constraint.isActive = true
return constraint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ final class UIViewPinTests: XCTestCase {

lazy var bView: UIView = {
let view = UIView(frame: .zero)
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()

Expand Down

0 comments on commit e760ae1

Please sign in to comment.