-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
131 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
iOS/Layover/Layover/Extensions/LayoverConstraint/LayoverConstraintWrapper+UIView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// LayoverConstraintWrapper+UIView.swift | ||
// Layover | ||
// | ||
// Created by 김인환 on 11/20/23. | ||
// Copyright © 2023 CodeBomber. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
extension LayoverConstraintWrapper where Base: UIView { | ||
|
||
func makeConstraints(_ closure: (ConstraintMaker) -> Void) { | ||
base.translatesAutoresizingMaskIntoConstraints = false | ||
closure(ConstraintMaker(base)) | ||
} | ||
} | ||
|
||
final class ConstraintMaker { | ||
let view: UIView | ||
|
||
init(_ view: UIView) { | ||
self.view = view | ||
} | ||
|
||
func topAnchor(equalTo anchor: NSLayoutYAxisAnchor, constant: CGFloat = 0) { | ||
view.topAnchor.constraint(equalTo: anchor, constant: constant).isActive = true | ||
} | ||
|
||
func bottomAnchor(equalTo anchor: NSLayoutYAxisAnchor, constant: CGFloat = 0) { | ||
view.bottomAnchor.constraint(equalTo: anchor, constant: constant).isActive = true | ||
} | ||
|
||
func leadingAnchor(equalTo anchor: NSLayoutXAxisAnchor, constant: CGFloat = 0) { | ||
view.leadingAnchor.constraint(equalTo: anchor, constant: constant).isActive = true | ||
} | ||
|
||
func trailingAnchor(equalTo anchor: NSLayoutXAxisAnchor, constant: CGFloat = 0) { | ||
view.trailingAnchor.constraint(equalTo: anchor, constant: constant).isActive = true | ||
} | ||
|
||
func widthAnchor(equalToConstant constant: CGFloat) { | ||
view.widthAnchor.constraint(equalToConstant: constant).isActive = true | ||
} | ||
|
||
func widthAnchor(equalTo anchor: NSLayoutDimension, multiplier: CGFloat = 1.0) { | ||
view.widthAnchor.constraint(equalTo: anchor, multiplier: multiplier).isActive = true | ||
} | ||
|
||
func heightAnchor(equalToConstant constant: CGFloat) { | ||
view.heightAnchor.constraint(equalToConstant: constant).isActive = true | ||
} | ||
|
||
func heightAnchor(equalTo anchor: NSLayoutDimension, multiplier: CGFloat = 1.0) { | ||
view.heightAnchor.constraint(equalTo: anchor, multiplier: multiplier).isActive = true | ||
} | ||
|
||
func verticalAnchor(equalTo relativeView: UIView) { | ||
topAnchor(equalTo: relativeView.topAnchor) | ||
bottomAnchor(equalTo: relativeView.bottomAnchor) | ||
} | ||
|
||
func horizontalAnchor(equalTo relativeView: UIView) { | ||
leadingAnchor(equalTo: relativeView.leadingAnchor) | ||
trailingAnchor(equalTo: relativeView.trailingAnchor) | ||
} | ||
|
||
func equalToSuperView() { | ||
guard let superview = view.superview else { return } | ||
verticalAnchor(equalTo: superview) | ||
horizontalAnchor(equalTo: superview) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
iOS/Layover/Layover/Extensions/LayoverConstraint/LayoverConstraintWrapper.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// LayoverConstraintWrapper.swift | ||
// Layover | ||
// | ||
// Created by 김인환 on 11/20/23. | ||
// Copyright © 2023 CodeBomber. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
struct LayoverConstraintWrapper<Base> { | ||
let base: Base | ||
init(base: Base) { | ||
self.base = base | ||
} | ||
} | ||
|
||
protocol LayoverConstraintCompatible { | ||
associatedtype LayoverConstraintBase | ||
|
||
var lor: LayoverConstraintWrapper<LayoverConstraintBase> { get } | ||
} | ||
|
||
extension LayoverConstraintCompatible { | ||
var lor: LayoverConstraintWrapper<Self> { | ||
get { | ||
return LayoverConstraintWrapper(base: self) | ||
} set { } | ||
} | ||
} | ||
|
||
extension UIView: LayoverConstraintCompatible { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters