Skip to content
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

[Feat] matching status #142

Merged
merged 11 commits into from
Jan 12, 2025
72 changes: 72 additions & 0 deletions walkmong/walkmong/Global/Components/CustomButtonView.swift
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()
}
}
}
131 changes: 131 additions & 0 deletions walkmong/walkmong/Global/Components/CustomView.swift
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
}
}
85 changes: 60 additions & 25 deletions walkmong/walkmong/Global/Extension/UIButton+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extension UIButton {
case smallSelection
case homeFilter
case customFilter
case largeSelectionCheck
case tag
}

Expand All @@ -42,6 +43,8 @@ extension UIButton {
} else {
configureHomeFilter(button: button, style: style, title: title)
}
case .largeSelectionCheck:
configureLargeSelectionCheck(button: button, style: style, title: title)
case .tag:
configureTagButton(button: button, style: style, title: title)
default:
Expand Down Expand Up @@ -82,7 +85,7 @@ extension UIButton {
: (type == .large ? .gray100 : .white)

switch type {
case .large, .homeFilter, .customFilter:
case .large, .homeFilter, .customFilter, .largeSelectionCheck:
return MainHighlightParagraphLabel(text: text, textColor: textColor)
case .largeSelection, .smallSelection:
return MainParagraphLabel(text: text, textColor: textColor)
Expand All @@ -97,10 +100,10 @@ extension UIButton {
}

private static func setButtonSizeConstraints(button: UIButton, width: CGFloat, height: CGFloat) {
NSLayoutConstraint.activate([
button.widthAnchor.constraint(equalToConstant: width),
button.heightAnchor.constraint(equalToConstant: height)
])
button.snp.makeConstraints { make in
make.width.equalTo(width)
make.height.equalTo(height)
}
}

private static func configureStyle(for button: UIButton, type: ButtonCategory, style: ButtonStyle) {
Expand All @@ -119,6 +122,9 @@ extension UIButton {
button.backgroundColor = style == .dark ? .gray600 : .gray100
case .customFilter:
break
case .largeSelectionCheck:
button.layer.cornerRadius = 5
button.backgroundColor = style == .light ? .gray100 : .mainBlue
case .tag:
button.layer.cornerRadius = 15
button.backgroundColor = style == .light ? .gray200 : .mainBlue
Expand Down Expand Up @@ -147,13 +153,9 @@ extension UIButton {

button.addSubview(stackView)

NSLayoutConstraint.activate([
stackView.leadingAnchor.constraint(equalTo: button.leadingAnchor, constant: 16),
stackView.trailingAnchor.constraint(equalTo: button.trailingAnchor, constant: -16),
stackView.topAnchor.constraint(equalTo: button.topAnchor, constant: 8),
stackView.bottomAnchor.constraint(equalTo: button.bottomAnchor, constant: -8),
icon.centerYAnchor.constraint(equalTo: label.centerYAnchor)
])
stackView.snp.makeConstraints { make in
make.edges.equalToSuperview().inset(UIEdgeInsets(top: 8, left: 16, bottom: 8, right: 16))
}

button.layer.cornerRadius = 18
button.backgroundColor = style == .light ? .gray100 : .gray600
Expand All @@ -162,6 +164,8 @@ extension UIButton {
func updateStyle(type: ButtonCategory, style: ButtonStyle) {
if type == .customFilter {
UIButton.configureCustomFilter(button: self, style: style, title: self.title(for: .normal) ?? "")
} else if type == .largeSelectionCheck {
UIButton.configureLargeSelectionCheck(button: self, style: style, title: self.title(for: .normal) ?? "")
} else {
let label = UIButton.labelForCategory(type: type, text: self.title(for: .normal) ?? "", style: style)
self.titleLabel?.font = label.font
Expand All @@ -184,13 +188,9 @@ extension UIButton {
label.translatesAutoresizingMaskIntoConstraints = false

button.addSubview(label)
NSLayoutConstraint.activate([
label.leadingAnchor.constraint(equalTo: button.leadingAnchor, constant: 16),
label.trailingAnchor.constraint(equalTo: button.trailingAnchor, constant: -16),
label.topAnchor.constraint(equalTo: button.topAnchor, constant: 8),
label.bottomAnchor.constraint(equalTo: button.bottomAnchor, constant: -8)
])

label.snp.makeConstraints { make in
make.edges.equalTo(button).inset(UIEdgeInsets(top: 8, left: 16, bottom: 8, right: 16))
}
button.layer.cornerRadius = 18
button.backgroundColor = style == .light ? .gray200 : .gray600
}
Expand All @@ -206,12 +206,9 @@ extension UIButton {
label.translatesAutoresizingMaskIntoConstraints = false
button.addSubview(label)

NSLayoutConstraint.activate([
label.leadingAnchor.constraint(equalTo: button.leadingAnchor, constant: 16),
label.trailingAnchor.constraint(equalTo: button.trailingAnchor, constant: -16),
label.topAnchor.constraint(equalTo: button.topAnchor, constant: 8),
label.bottomAnchor.constraint(equalTo: button.bottomAnchor, constant: -8)
])
label.snp.makeConstraints { make in
make.edges.equalToSuperview().inset(UIEdgeInsets(top: 8, left: 16, bottom: 8, right: 16))
}

button.layer.cornerRadius = 18
button.backgroundColor = style == .light ? .gray100 : .gray600
Expand All @@ -227,6 +224,44 @@ extension UIButton {
}
}

private static func configureLargeSelectionCheck(button: UIButton, style: ButtonStyle, title: String) {
let textColor: UIColor = style == .light ? .gray500 : .white
let customFont = UIFont(name: "Pretendard-SemiBold", size: 16)!

button.setTitle(title, for: .normal)
button.setTitleColor(textColor, for: .normal)
button.titleLabel?.font = customFont
button.contentHorizontalAlignment = .leading
button.titleEdgeInsets = UIEdgeInsets(top: 0, left: 24, bottom: 0, right: 0)

let icon = UIImageView()
icon.translatesAutoresizingMaskIntoConstraints = false
icon.image = UIImage(named: style == .light ? "myPageReportUnchecked" : "checkWhiteIcon")
icon.contentMode = .scaleAspectFit

button.subviews
.filter { $0 is UIImageView }
.forEach { $0.removeFromSuperview() }
button.addSubview(icon)

icon.snp.makeConstraints { make in
make.trailing.equalTo(button).offset(-24)
make.centerY.equalTo(button)
make.width.height.equalTo(24)
}

button.snp.makeConstraints { make in
make.height.equalTo(46)
}

button.layer.cornerRadius = 5
button.backgroundColor = style == .light ? .gray100 : .mainBlue
}

func setStyle(_ style: ButtonStyle, type: ButtonCategory) {
self.updateStyle(type: type, style: style)
}

private static func configureTagButton(button: UIButton, style: ButtonStyle, title: String) {
let textColor: UIColor = .mainBlack
let backgroundColor: UIColor = style == .light ? .gray200 : .mainBlue
Expand Down
3 changes: 2 additions & 1 deletion walkmong/walkmong/Global/Extension/UIImage+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ extension UIImage {

// 이미지 설정
if let imageName = imageName {
imageView.image = UIImage(named: imageName)
let image = UIImage(named: imageName)?.withRenderingMode(.alwaysTemplate)
imageView.image = image
}

// 공통 속성
Expand Down
Loading