-
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
22 changed files
with
1,876 additions
and
68 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
walkmong/walkmong/Global/Components/CustomButtonView.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,72 @@ | ||
// | ||
// CustomButtonView.swift | ||
// walkmong | ||
// | ||
// Created by ์ ํธ์ฐ on 1/11/25. | ||
// | ||
|
||
import UIKit | ||
import SnapKit | ||
|
||
final class CustomButtonView: UIView { | ||
|
||
// MARK: - Initializer | ||
init( | ||
backgroundColor: UIColor, | ||
cornerRadius: CGFloat, | ||
text: String, | ||
textColor: UIColor, | ||
iconName: String? = nil, | ||
iconSpacing: CGFloat = 8 | ||
) { | ||
super.init(frame: .zero) | ||
setupView( | ||
backgroundColor: backgroundColor, | ||
cornerRadius: cornerRadius, | ||
text: text, | ||
textColor: textColor, | ||
iconName: iconName, | ||
iconSpacing: iconSpacing | ||
) | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
// MARK: - Private Methods | ||
private func setupView( | ||
backgroundColor: UIColor, | ||
cornerRadius: CGFloat, | ||
text: String, | ||
textColor: UIColor, | ||
iconName: String?, | ||
iconSpacing: CGFloat | ||
) { | ||
self.backgroundColor = backgroundColor | ||
self.layer.cornerRadius = cornerRadius | ||
self.layer.masksToBounds = true | ||
|
||
let label = UILabel() | ||
label.text = text | ||
label.textColor = textColor | ||
label.font = UIFont(name: "Pretendard-SemiBold", size: 16) | ||
|
||
let stackView = UIStackView() | ||
stackView.axis = .horizontal | ||
stackView.alignment = .center | ||
stackView.spacing = iconSpacing | ||
stackView.addArrangedSubview(label) | ||
|
||
if let iconName = iconName, let iconImage = UIImage(named: iconName) { | ||
let icon = UIImageView(image: iconImage) | ||
icon.contentMode = .scaleAspectFit | ||
stackView.addArrangedSubview(icon) | ||
} | ||
|
||
addSubview(stackView) | ||
stackView.snp.makeConstraints { make in | ||
make.center.equalToSuperview() | ||
} | ||
} | ||
} |
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,131 @@ | ||
// | ||
// CustomView.swift | ||
// walkmong | ||
// | ||
// Created by ์ ํธ์ฐ on 1/11/25. | ||
// | ||
|
||
import UIKit | ||
import SnapKit | ||
|
||
class CustomView: UIView { | ||
static func createCustomView( | ||
titleText: String?, | ||
warningText: String? = nil, | ||
warningColor: UIColor? = nil, | ||
centerLabelText: String? = nil, | ||
contentText: String? = nil, | ||
contentTextColor: UIColor = .gray600, | ||
contentTextAlignment: NSTextAlignment = .left, | ||
layoutOption: LayoutOption = .default | ||
) -> UIView { | ||
let containerView = UIView() | ||
var lastView: UIView = containerView | ||
|
||
if let titleText = titleText { | ||
let titleLabel = SmallTitleLabel(text: titleText, textColor: .gray600) | ||
containerView.addSubview(titleLabel) | ||
titleLabel.snp.makeConstraints { make in | ||
make.top.equalToSuperview() | ||
make.leading.trailing.equalToSuperview() | ||
} | ||
lastView = titleLabel | ||
} | ||
|
||
if let warningText = warningText, let warningColor = warningColor { | ||
let warningIcon = UIImage.createImageView( | ||
named: "WarningIcon", | ||
contentMode: .scaleAspectFit | ||
) | ||
warningIcon.tintColor = warningColor | ||
containerView.addSubview(warningIcon) | ||
|
||
let warningLabel = SmallMainHighlightParagraphLabel(text: warningText, textColor: warningColor) | ||
containerView.addSubview(warningLabel) | ||
|
||
warningIcon.snp.makeConstraints { make in | ||
make.top.equalTo(lastView.snp.bottom).offset(8) | ||
make.leading.equalToSuperview() | ||
} | ||
|
||
warningLabel.snp.makeConstraints { make in | ||
make.centerY.equalTo(warningIcon.snp.centerY) | ||
make.leading.equalTo(warningIcon.snp.trailing).offset(4) | ||
make.trailing.equalToSuperview() | ||
} | ||
|
||
lastView = warningLabel | ||
} | ||
|
||
let whiteBackgroundView = UIView() | ||
whiteBackgroundView.backgroundColor = .white | ||
whiteBackgroundView.layer.cornerRadius = 5 | ||
whiteBackgroundView.clipsToBounds = true | ||
containerView.addSubview(whiteBackgroundView) | ||
whiteBackgroundView.snp.makeConstraints { make in | ||
make.top.equalTo(lastView.snp.bottom).offset(16) | ||
make.leading.trailing.equalToSuperview() | ||
make.bottom.equalToSuperview() | ||
} | ||
|
||
switch layoutOption { | ||
case .default: | ||
if let centerLabelText = centerLabelText { | ||
let centerLabel = MainHighlightParagraphLabel(text: centerLabelText, textColor: .gray600) | ||
whiteBackgroundView.addSubview(centerLabel) | ||
centerLabel.snp.makeConstraints { make in | ||
make.center.equalToSuperview() | ||
} | ||
} else if let contentText = contentText { | ||
let contentLabel = MainParagraphLabel(text: contentText, textColor: contentTextColor) | ||
contentLabel.numberOfLines = 0 | ||
contentLabel.lineBreakMode = .byWordWrapping | ||
contentLabel.textAlignment = contentTextAlignment | ||
whiteBackgroundView.addSubview(contentLabel) | ||
contentLabel.snp.makeConstraints { make in | ||
make.top.bottom.equalToSuperview().inset(12) | ||
make.leading.trailing.equalToSuperview().inset(16) | ||
} | ||
} | ||
case .leftAlignedContent: | ||
if let contentText = contentText { | ||
let contentLabel = MainParagraphLabel(text: contentText, textColor: contentTextColor) | ||
contentLabel.numberOfLines = 0 | ||
contentLabel.lineBreakMode = .byWordWrapping | ||
contentLabel.textAlignment = .left | ||
whiteBackgroundView.addSubview(contentLabel) | ||
contentLabel.snp.makeConstraints { make in | ||
make.edges.equalToSuperview().inset(12) | ||
} | ||
} | ||
case .centerAndLeftAligned: | ||
if let centerLabelText = centerLabelText { | ||
let centerLabel = MainHighlightParagraphLabel(text: centerLabelText, textColor: .gray600) | ||
whiteBackgroundView.addSubview(centerLabel) | ||
centerLabel.snp.makeConstraints { make in | ||
make.top.leading.trailing.equalToSuperview().inset(12) | ||
} | ||
|
||
if let contentText = contentText { | ||
let contentLabel = MainParagraphLabel(text: contentText, textColor: contentTextColor) | ||
contentLabel.numberOfLines = 0 | ||
contentLabel.lineBreakMode = .byWordWrapping | ||
contentLabel.textAlignment = contentTextAlignment | ||
whiteBackgroundView.addSubview(contentLabel) | ||
contentLabel.snp.makeConstraints { make in | ||
make.top.equalTo(centerLabel.snp.bottom).offset(10) | ||
make.leading.trailing.bottom.equalToSuperview().inset(12) | ||
} | ||
} | ||
} | ||
} | ||
|
||
return containerView | ||
} | ||
|
||
enum LayoutOption { | ||
case `default` | ||
case leftAlignedContent | ||
case centerAndLeftAligned | ||
} | ||
} |
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
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
Oops, something went wrong.