Skip to content

Commit

Permalink
[Feat] matching status (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
fnfn0901 authored Jan 12, 2025
2 parents 5b64978 + 309c216 commit 7716af8
Show file tree
Hide file tree
Showing 22 changed files with 1,876 additions and 68 deletions.
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
}
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ protocol MatchingDogInformationViewDelegate: AnyObject {
func applyWalkButtonTapped()
}

class MatchingDogInformationView: UIView, UIScrollViewDelegate {
final class MatchingDogInformationView: UIView, UIScrollViewDelegate {

// MARK: - Delegate
weak var delegate: MatchingDogInformationViewDelegate?
Expand All @@ -23,9 +23,7 @@ class MatchingDogInformationView: UIView, UIScrollViewDelegate {
private let ownerInfoFrame = OwnerInfoView()
private let buttonFrame = UIView()

private let walkTalkButton: UIView = MatchingDogInformationView.createRoundedButton(
backgroundColor: UIColor.gray100, cornerRadius: 15
)
private let walkTalkButton: UIView = UIView.createRoundedView(backgroundColor: UIColor.gray100, cornerRadius: 15)

private let applyWalkButton = UIButton.createStyledButton(type: .large, style: .dark, title: "์‚ฐ์ฑ… ์ง€์›ํ•˜๊ธฐ")
// MARK: - Initializer
Expand Down Expand Up @@ -244,13 +242,6 @@ class MatchingDogInformationView: UIView, UIScrollViewDelegate {
}

// MARK: - Helper Methods
private static func createRoundedButton(backgroundColor: UIColor, cornerRadius: CGFloat) -> UIView {
let view = UIView()
view.backgroundColor = backgroundColor
view.layer.cornerRadius = cornerRadius
return view
}

func configureImages(with imageUrls: [String?]) {
guard let firstImageUrl = imageUrls.first else {
imageView.image = UIImage(named: "placeholder")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ class OwnerInfoView: UIView {
)

private let nameLabel = UpperTitleLabel(text: "", textColor: .gray600)

private let ageLabel = SmallMainParagraphLabel(text: "", textColor: .gray600)

private let separatorLabel = SmallMainParagraphLabel(text: "", textColor: .gray600)

private let genderLabel = SmallMainParagraphLabel(text: "", textColor: .gray600)

private let infoLabel = SmallMainParagraphLabel(text: "", textColor: .gray600)
private let starIcon = UIImage.createImageView(named: "starIcon.png")

private let ratingLabel = SmallMainHighlightParagraphLabel(text: "", textColor: .mainBlue)
Expand All @@ -44,8 +38,7 @@ class OwnerInfoView: UIView {
layer.cornerRadius = 20

let subviews = [
titleLabel, profileImageView, nameLabel, ageLabel, separatorLabel,
genderLabel, starIcon, ratingLabel, locationIcon, locationLabel
titleLabel, profileImageView, nameLabel, infoLabel, starIcon, ratingLabel, locationIcon, locationLabel
]
subviews.forEach { addSubview($0) }
setupConstraints()
Expand All @@ -68,23 +61,13 @@ class OwnerInfoView: UIView {
make.leading.equalTo(profileImageView.snp.trailing).offset(12)
}

ageLabel.snp.makeConstraints { make in
make.leading.equalTo(nameLabel.snp.trailing).offset(8)
make.centerY.equalTo(nameLabel.snp.centerY)
}

separatorLabel.snp.makeConstraints { make in
make.leading.equalTo(ageLabel.snp.trailing).offset(4)
make.centerY.equalTo(ageLabel.snp.centerY)
}

genderLabel.snp.makeConstraints { make in
make.leading.equalTo(separatorLabel.snp.trailing).offset(4)
make.centerY.equalTo(separatorLabel.snp.centerY)
infoLabel.snp.makeConstraints { make in
make.centerY.equalTo(nameLabel)
make.leading.equalTo(nameLabel.snp.trailing).offset(24)
}

starIcon.snp.makeConstraints { make in
make.top.equalTo(ageLabel.snp.bottom).offset(16)
make.top.equalTo(infoLabel.snp.bottom).offset(16)
make.leading.equalTo(nameLabel.snp.leading)
make.width.height.equalTo(17)
}
Expand Down Expand Up @@ -119,8 +102,8 @@ class OwnerInfoView: UIView {
) {
profileImageView.setImage(from: ownerProfile, placeholder: "profileExample")
nameLabel.text = ownerName
ageLabel.text = formatAge(ownerAge)
genderLabel.text = ownerGender == "FEMALE" ? "์—ฌ์„ฑ" : "๋‚จ์„ฑ"
let genderText = ownerGender == "FEMALE" ? "์—ฌ์„ฑ" : "๋‚จ์„ฑ"
infoLabel.text = "\(ownerAge)์‚ด ยท \(genderText)"
ratingLabel.text = String(format: "%.1f", ownerRate)
locationLabel.text = "\(dongAddress) \(formatDistance(distance))"
}
Expand All @@ -134,22 +117,6 @@ class OwnerInfoView: UIView {
return label
}

private func formatAge(_ age: Int) -> String {
let ageGroup = (age / 10) * 10
let ageCategory: String
switch age % 10 {
case 0...2:
ageCategory = "์ดˆ๋ฐ˜"
case 3...6:
ageCategory = "์ค‘๋ฐ˜"
case 7...9:
ageCategory = "ํ›„๋ฐ˜"
default:
ageCategory = ""
}
return "\(ageGroup)๋Œ€ \(ageCategory)"
}

private func formatDistance(_ distance: Double) -> String {
if distance < 1000 {
return "\(Int(distance))m"
Expand Down
Loading

0 comments on commit 7716af8

Please sign in to comment.