-
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
1 parent
835bd0b
commit ef53ffa
Showing
2 changed files
with
71 additions
and
0 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
59 changes: 59 additions & 0 deletions
59
GEON-PPANG-iOS/Core/DesignSystem/UIComponents/View/StackView/GBStackView.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,59 @@ | ||
// | ||
// GBStackView.swift | ||
// GEON-PPANG-iOS | ||
// | ||
// Created by JEONGEUN KIM on 7/10/24. | ||
// | ||
|
||
import UIKit | ||
|
||
enum GBStackType { | ||
case big | ||
case small | ||
|
||
var images: [UIImage] { | ||
switch self { | ||
case .big: return [.haccpMark28px, .veganMark28px, .gmoMark28px] | ||
case .small: return [.haccpMark22px, .veganMark22px, .gmoMark22px] | ||
} | ||
} | ||
|
||
var size: Int { | ||
switch self { | ||
case .big: return 28 | ||
case .small: return 24 | ||
} | ||
} | ||
} | ||
|
||
final class GBStackView: UIStackView { | ||
|
||
init(type: GBStackType, data: [Bool]) { | ||
super.init(frame: .zero) | ||
setUI() | ||
addCertifiedImageViews(type: type, data: data) | ||
} | ||
|
||
required init(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
private func setUI() { | ||
axis = .horizontal | ||
spacing = -8 | ||
} | ||
|
||
private func addCertifiedImageViews(type: GBStackType, data: [Bool]) { | ||
data.enumerated() | ||
.filter { $0.element } | ||
.map { $0.offset } | ||
.forEach { index in | ||
let imageView = UIImageView(image: type.images[index]) | ||
imageView.contentMode = .topLeft | ||
addArrangedSubview(imageView) | ||
imageView.snp.makeConstraints { | ||
$0.size.equalTo(type.size) | ||
} | ||
} | ||
} | ||
} |