-
Notifications
You must be signed in to change notification settings - Fork 0
feat: LayoverConstraintWrapper 구현 #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
loinsir
wants to merge
3
commits into
iOS/dev
Choose a base branch
from
iOS/feat#49
base: iOS/dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
81 changes: 81 additions & 0 deletions
81
iOS/Layover/Layover/Extensions/LayoverConstraint/LayoverConstraintWrapper+UIView.swift
This file contains hidden or 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,81 @@ | ||
// | ||
// 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 | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이거 음수 -> 양수로 변환해주세요 |
||
|
||
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 centerXAnchor(equalTo anchor: NSLayoutAnchor<NSLayoutXAxisAnchor>) { | ||
view.centerXAnchor.constraint(equalTo: anchor).isActive = true | ||
} | ||
|
||
func centerYAnchor(equalTo anchor: NSLayoutAnchor<NSLayoutYAxisAnchor>) { | ||
view.centerYAnchor.constraint(equalTo: anchor).isActive = true | ||
} | ||
|
||
func equalToSuperView() { | ||
guard let superview = view.superview else { return } | ||
verticalAnchor(equalTo: superview) | ||
horizontalAnchor(equalTo: superview) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
iOS/Layover/Layover/Extensions/LayoverConstraint/LayoverConstraintWrapper.swift
This file contains hidden or 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,29 @@ | ||
// | ||
// LayoverConstraintWrapper.swift | ||
// Layover | ||
// | ||
// Created by 김인환 on 11/20/23. | ||
// Copyright © 2023 CodeBomber. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
struct LayoverConstraintWrapper<Base> { | ||
let base: Base | ||
} | ||
|
||
protocol LayoverConstraintCompatible { | ||
associatedtype LayoverConstraintBase | ||
|
||
var lor: LayoverConstraintWrapper<LayoverConstraintBase> { get } | ||
} | ||
|
||
extension LayoverConstraintCompatible { | ||
var lor: LayoverConstraintWrapper<Self> { | ||
get { | ||
return LayoverConstraintWrapper(base: self) | ||
} | ||
} | ||
} | ||
|
||
extension UIView: LayoverConstraintCompatible { } |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updateConstraints도 구현해주세요..
나중에 갖다 써야지..ㅎ