From 9d39ef0f376e6df65ced457ad9a84fda95858e27 Mon Sep 17 00:00:00 2001 From: Kyxxn Date: Sat, 9 Nov 2024 03:28:16 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=EC=98=A4=ED=86=A0=EB=A0=88?= =?UTF-8?q?=EC=9D=B4=EC=95=84=EC=9B=83=20=ED=8E=B8=EC=9D=98=20Anchor=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Source/Extensions/UIView+Anchor.swift | 128 ++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 MemorialHouse/MHPresentation/MHPresentation/Source/Extensions/UIView+Anchor.swift diff --git a/MemorialHouse/MHPresentation/MHPresentation/Source/Extensions/UIView+Anchor.swift b/MemorialHouse/MHPresentation/MHPresentation/Source/Extensions/UIView+Anchor.swift new file mode 100644 index 00000000..386824a8 --- /dev/null +++ b/MemorialHouse/MHPresentation/MHPresentation/Source/Extensions/UIView+Anchor.swift @@ -0,0 +1,128 @@ +import UIKit + +extension UIView { + func setAnchor( + top: NSLayoutYAxisAnchor? = nil, + constantTop: CGFloat = 0, + leading: NSLayoutXAxisAnchor? = nil, + constantLeading: CGFloat = 0, + bottom: NSLayoutYAxisAnchor? = nil, + constantBottom: CGFloat = 0, + trailing: NSLayoutXAxisAnchor? = nil, + constantTrailing: CGFloat = 0, + width: CGFloat? = nil, + height: CGFloat? = nil + ) { + self.translatesAutoresizingMaskIntoConstraints = false + if let top { + self.topAnchor.constraint(equalTo: top, constant: constantTop).isActive = true + } + + if let leading { + self.leadingAnchor.constraint(equalTo: leading, constant: constantLeading).isActive = true + } + + if let bottom { + self.bottomAnchor.constraint(equalTo: bottom, constant: -constantBottom).isActive = true + } + + if let trailing { + self.trailingAnchor.constraint(equalTo: trailing, constant: -constantTrailing).isActive = true + } + + if let width { + self.widthAnchor.constraint(equalToConstant: width).isActive = true + } + + if let height { + self.heightAnchor.constraint(equalToConstant: height).isActive = true + } + } + + func setTop(anchor: NSLayoutYAxisAnchor, constant: CGFloat) { + self.translatesAutoresizingMaskIntoConstraints = false + self.topAnchor.constraint(equalTo: anchor, constant: constant).isActive = true + } + + func setLeading(anchor: NSLayoutXAxisAnchor, constant: CGFloat) { + self.translatesAutoresizingMaskIntoConstraints = false + self.leadingAnchor.constraint(equalTo: anchor, constant: constant).isActive = true + } + + func setBottom(anchor: NSLayoutYAxisAnchor, constant: CGFloat) { + self.translatesAutoresizingMaskIntoConstraints = false + self.bottomAnchor.constraint(equalTo: anchor, constant: -constant).isActive = true + } + + func setTrailing(anchor: NSLayoutXAxisAnchor, constant: CGFloat) { + self.translatesAutoresizingMaskIntoConstraints = false + self.trailingAnchor.constraint(equalTo: anchor, constant: -constant).isActive = true + } + + func setCenter(view: UIView, offset: CGPoint) { + self.translatesAutoresizingMaskIntoConstraints = false + self.centerXAnchor.constraint(equalTo: view.centerXAnchor, constant: offset.x).isActive = true + self.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: offset.y).isActive = true + } + + func setHorizontal(view: UIView, constant: CGFloat) { + self.translatesAutoresizingMaskIntoConstraints = false + self.setLeading(anchor: view.leadingAnchor, constant: constant) + self.setTrailing(anchor: view.trailingAnchor, constant: constant) + } + + func setHorizontal(layoutGuide: UILayoutGuide, constant: CGFloat) { + self.translatesAutoresizingMaskIntoConstraints = false + self.setLeading(anchor: layoutGuide.leadingAnchor, constant: constant) + self.setTrailing(anchor: layoutGuide.trailingAnchor, constant: constant) + } + + func setVertical(layoutGuide: UILayoutGuide, constant: CGFloat) { + self.translatesAutoresizingMaskIntoConstraints = false + self.setTop(anchor: layoutGuide.topAnchor, constant: constant) + self.setBottom(anchor: layoutGuide.bottomAnchor, constant: constant) + } + + func setVertical(view: UIView, constant: CGFloat) { + self.translatesAutoresizingMaskIntoConstraints = false + self.setTop(anchor: view.topAnchor, constant: constant) + self.setBottom(anchor: view.bottomAnchor, constant: constant) + } + + func setCenterX(view: UIView, constant: CGFloat = 0) { + self.translatesAutoresizingMaskIntoConstraints = false + self.centerXAnchor.constraint(equalTo: view.centerXAnchor, constant: constant).isActive = true + } + + func setCenterY(view: UIView, constant: CGFloat = 0) { + self.translatesAutoresizingMaskIntoConstraints = false + self.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: constant).isActive = true + } + + func setWidthAndHeight(width: CGFloat, height: CGFloat) { + self.translatesAutoresizingMaskIntoConstraints = false + self.widthAnchor.constraint(equalToConstant: width).isActive = true + self.heightAnchor.constraint(equalToConstant: height).isActive = true + } + + func setHeight(_ height: CGFloat) { + self.translatesAutoresizingMaskIntoConstraints = false + self.heightAnchor.constraint(equalToConstant: height).isActive = true + } + + func setWidth(_ width: CGFloat) { + self.translatesAutoresizingMaskIntoConstraints = false + self.widthAnchor.constraint(equalToConstant: width).isActive = true + } + + func fillSuperview() { + self.translatesAutoresizingMaskIntoConstraints = false + guard let view = self.superview else { return } + self.setAnchor( + top: view.safeAreaLayoutGuide.topAnchor, + leading: view.leadingAnchor, + bottom: view.safeAreaLayoutGuide.bottomAnchor, + trailing: view.trailingAnchor + ) + } +} From db4cb599815a598a3bd573ea825996aaab6c6057 Mon Sep 17 00:00:00 2001 From: Kyxxn Date: Sat, 9 Nov 2024 03:28:35 +0900 Subject: [PATCH 2/4] =?UTF-8?q?refactor:=20=EC=BB=A4=EC=8A=A4=ED=85=80=20?= =?UTF-8?q?=EC=95=A8=EB=B2=94=20=EA=B5=AC=ED=98=84=EB=B6=80=20Anchor=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=EB=A1=9C=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CustomAlbum/CustomAlbumCollectionViewCell.swift | 8 +------- .../Source/CustomAlbum/CustomAlbumViewController.swift | 9 +-------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/MemorialHouse/MHPresentation/MHPresentation/Source/CustomAlbum/CustomAlbumCollectionViewCell.swift b/MemorialHouse/MHPresentation/MHPresentation/Source/CustomAlbum/CustomAlbumCollectionViewCell.swift index f8506a17..98c0969e 100644 --- a/MemorialHouse/MHPresentation/MHPresentation/Source/CustomAlbum/CustomAlbumCollectionViewCell.swift +++ b/MemorialHouse/MHPresentation/MHPresentation/Source/CustomAlbum/CustomAlbumCollectionViewCell.swift @@ -4,7 +4,6 @@ final class CustomAlbumCollectionViewCell: UICollectionViewCell { // MARK: - Properties private let photoImageView: UIImageView = { let imageView = UIImageView(image: nil) - imageView.translatesAutoresizingMaskIntoConstraints = false imageView.contentMode = .scaleAspectFill imageView.clipsToBounds = true @@ -40,12 +39,7 @@ final class CustomAlbumCollectionViewCell: UICollectionViewCell { private func configureConstraints() { contentView.addSubview(photoImageView) - NSLayoutConstraint.activate([ - photoImageView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), - photoImageView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), - photoImageView.topAnchor.constraint(equalTo: contentView.topAnchor), - photoImageView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor) - ]) + photoImageView.fillSuperview() } // MARK: - Set Cell Image diff --git a/MemorialHouse/MHPresentation/MHPresentation/Source/CustomAlbum/CustomAlbumViewController.swift b/MemorialHouse/MHPresentation/MHPresentation/Source/CustomAlbum/CustomAlbumViewController.swift index ddfa62a5..f56995ad 100644 --- a/MemorialHouse/MHPresentation/MHPresentation/Source/CustomAlbum/CustomAlbumViewController.swift +++ b/MemorialHouse/MHPresentation/MHPresentation/Source/CustomAlbum/CustomAlbumViewController.swift @@ -15,7 +15,6 @@ final class CustomAlbumViewController: UIViewController { flowLayout.minimumInteritemSpacing = 5 flowLayout.scrollDirection = .vertical let collectionView = UICollectionView(frame: .zero, collectionViewLayout: flowLayout) - collectionView.translatesAutoresizingMaskIntoConstraints = false return collectionView }() @@ -45,13 +44,7 @@ final class CustomAlbumViewController: UIViewController { private func configureConstraints() { view.addSubview(albumCollectionView) - - NSLayoutConstraint.activate([ - albumCollectionView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), - albumCollectionView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor), - albumCollectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor), - albumCollectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor) - ]) + albumCollectionView.fillSuperview() } // MARK: - Open Camera From d2791229d6e40aaa1716f7e57c56fd50ee099e83 Mon Sep 17 00:00:00 2001 From: Kyxxn Date: Sat, 9 Nov 2024 03:28:44 +0900 Subject: [PATCH 3/4] =?UTF-8?q?chore:=20project=20pbx=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=20=EC=97=85=EB=A1=9C=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MHPresentation/MHPresentation.xcodeproj/project.pbxproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/MemorialHouse/MHPresentation/MHPresentation.xcodeproj/project.pbxproj b/MemorialHouse/MHPresentation/MHPresentation.xcodeproj/project.pbxproj index 503ae2c7..44e451b1 100644 --- a/MemorialHouse/MHPresentation/MHPresentation.xcodeproj/project.pbxproj +++ b/MemorialHouse/MHPresentation/MHPresentation.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 0E5C13C62CDE8D1D005406B3 /* UIView+Anchor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E5C13C52CDE8D19005406B3 /* UIView+Anchor.swift */; }; 0E7F29192CDB52DE007D4F2B /* UIFont+Ownglyph.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E7F29182CDB52D4007D4F2B /* UIFont+Ownglyph.swift */; }; 0E7F291B2CDB530E007D4F2B /* UILabel+Style.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E7F291A2CDB5302007D4F2B /* UILabel+Style.swift */; }; 0E7F291D2CDB53B5007D4F2B /* Colors.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0E7F291C2CDB53B5007D4F2B /* Colors.xcassets */; }; @@ -22,6 +23,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 0E5C13C52CDE8D19005406B3 /* UIView+Anchor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Anchor.swift"; sourceTree = ""; }; 0E7F28EC2CDA6C06007D4F2B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 0E7F29182CDB52D4007D4F2B /* UIFont+Ownglyph.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIFont+Ownglyph.swift"; sourceTree = ""; }; 0E7F291A2CDB5302007D4F2B /* UILabel+Style.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UILabel+Style.swift"; sourceTree = ""; }; @@ -80,6 +82,7 @@ 0E7F29172CDB52CC007D4F2B /* Extensions */ = { isa = PBXGroup; children = ( + 0E5C13C52CDE8D19005406B3 /* UIView+Anchor.swift */, 0E7F291A2CDB5302007D4F2B /* UILabel+Style.swift */, 0E7F29182CDB52D4007D4F2B /* UIFont+Ownglyph.swift */, A840E5922CDE266F002A1C94 /* UICollectionViewCell+Identifier.swift */, @@ -247,6 +250,7 @@ A8A32C532CDBB9980078B4F6 /* CustomAlbumViewController.swift in Sources */, A840E5932CDE266F002A1C94 /* UICollectionViewCell+Identifier.swift in Sources */, 0E7F291B2CDB530E007D4F2B /* UILabel+Style.swift in Sources */, + 0E5C13C62CDE8D1D005406B3 /* UIView+Anchor.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; From d06b4206534c32a2d7737f77b6081e2015e0a6d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=ED=9A=A8=EC=A4=80?= Date: Sat, 9 Nov 2024 15:08:14 +0900 Subject: [PATCH 4/4] =?UTF-8?q?refactor:=20setVertical=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EC=88=9C=EC=84=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 00me <62226667+k2645@users.noreply.github.com> --- .../Source/Extensions/UIView+Anchor.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/MemorialHouse/MHPresentation/MHPresentation/Source/Extensions/UIView+Anchor.swift b/MemorialHouse/MHPresentation/MHPresentation/Source/Extensions/UIView+Anchor.swift index 386824a8..07274f0f 100644 --- a/MemorialHouse/MHPresentation/MHPresentation/Source/Extensions/UIView+Anchor.swift +++ b/MemorialHouse/MHPresentation/MHPresentation/Source/Extensions/UIView+Anchor.swift @@ -77,18 +77,18 @@ extension UIView { self.setTrailing(anchor: layoutGuide.trailingAnchor, constant: constant) } - func setVertical(layoutGuide: UILayoutGuide, constant: CGFloat) { - self.translatesAutoresizingMaskIntoConstraints = false - self.setTop(anchor: layoutGuide.topAnchor, constant: constant) - self.setBottom(anchor: layoutGuide.bottomAnchor, constant: constant) - } - func setVertical(view: UIView, constant: CGFloat) { self.translatesAutoresizingMaskIntoConstraints = false self.setTop(anchor: view.topAnchor, constant: constant) self.setBottom(anchor: view.bottomAnchor, constant: constant) } + func setVertical(layoutGuide: UILayoutGuide, constant: CGFloat) { + self.translatesAutoresizingMaskIntoConstraints = false + self.setTop(anchor: layoutGuide.topAnchor, constant: constant) + self.setBottom(anchor: layoutGuide.bottomAnchor, constant: constant) + } + func setCenterX(view: UIView, constant: CGFloat = 0) { self.translatesAutoresizingMaskIntoConstraints = false self.centerXAnchor.constraint(equalTo: view.centerXAnchor, constant: constant).isActive = true