|
| 1 | +// |
| 2 | +// RegisterEmotionButtonView.swift |
| 3 | +// Presentation |
| 4 | +// |
| 5 | +// Created by 최정인 on 8/15/25. |
| 6 | +// |
| 7 | + |
| 8 | +import SnapKit |
| 9 | +import UIKit |
| 10 | + |
| 11 | +protocol RegisterEmotionButtonViewDelegate: AnyObject { |
| 12 | + func registerEmotionButtonViewDidTapRegisterButton(_ sender: RegisterEmotionButtonView) |
| 13 | +} |
| 14 | + |
| 15 | +final class RegisterEmotionButtonView: UIView { |
| 16 | + private enum Layout { |
| 17 | + static let cornerRadius: CGFloat = 12 |
| 18 | + static let emotionOrbImageViewLeadingSpacing: CGFloat = 13 |
| 19 | + static let emotionOrbImageViewSize: CGFloat = 34 |
| 20 | + static let registerEmotionLabelLeadingSpacing: CGFloat = 5 |
| 21 | + static let registerEmotionButtonCornerRadius: CGFloat = 8 |
| 22 | + static let registerEmotionButtonTrailingSpacing: CGFloat = 19 |
| 23 | + static let registerEmotionButtonWidth: CGFloat = 74 |
| 24 | + static let registerEmotionButtonHeight: CGFloat = 38 |
| 25 | + } |
| 26 | + |
| 27 | + private let emotionOrbImageView = UIImageView() |
| 28 | + private let registerEmotionLabel = UILabel() |
| 29 | + private let registerEmotionButton = UIButton() |
| 30 | + weak var delegate: RegisterEmotionButtonViewDelegate? |
| 31 | + |
| 32 | + init() { |
| 33 | + super.init(frame: .zero) |
| 34 | + configureAttribute() |
| 35 | + configureLayout() |
| 36 | + } |
| 37 | + |
| 38 | + required init?(coder: NSCoder) { |
| 39 | + fatalError("init(coder:) has not been implemented") |
| 40 | + } |
| 41 | + |
| 42 | + private func configureAttribute() { |
| 43 | + emotionOrbImageView.image = BitnagilGraphic.defaultEmotionGraphic |
| 44 | + emotionOrbImageView.contentMode = .scaleAspectFit |
| 45 | + |
| 46 | + registerEmotionLabel.text = "내 기분에 맞는 루틴 추천받기" |
| 47 | + registerEmotionLabel.font = BitnagilFont(style: .body2, weight: .semiBold).font |
| 48 | + registerEmotionLabel.textColor = .white |
| 49 | + |
| 50 | + var buttonConfiguration = UIButton.Configuration.filled() |
| 51 | + buttonConfiguration.baseBackgroundColor = BitnagilColor.orange500 |
| 52 | + buttonConfiguration.background.cornerRadius = Layout.registerEmotionButtonCornerRadius |
| 53 | + buttonConfiguration.attributedTitle = AttributedString( |
| 54 | + "추천받기", |
| 55 | + attributes: .init([.font: BitnagilFont(style: .caption1, weight: .semiBold).font])) |
| 56 | + buttonConfiguration.baseForegroundColor = .white |
| 57 | + registerEmotionButton.configuration = buttonConfiguration |
| 58 | + registerEmotionButton.addAction( |
| 59 | + UIAction { [weak self] _ in |
| 60 | + guard let self else { return } |
| 61 | + self.delegate?.registerEmotionButtonViewDidTapRegisterButton(self) |
| 62 | + }, |
| 63 | + for: .touchUpInside) |
| 64 | + } |
| 65 | + |
| 66 | + private func configureLayout() { |
| 67 | + backgroundColor = BitnagilColor.gray10 |
| 68 | + layer.masksToBounds = true |
| 69 | + layer.cornerRadius = Layout.cornerRadius |
| 70 | + |
| 71 | + [emotionOrbImageView, registerEmotionLabel, registerEmotionButton].forEach { |
| 72 | + addSubview($0) |
| 73 | + } |
| 74 | + |
| 75 | + emotionOrbImageView.snp.makeConstraints { make in |
| 76 | + make.leading.equalToSuperview().offset(Layout.emotionOrbImageViewLeadingSpacing) |
| 77 | + make.centerY.equalToSuperview() |
| 78 | + make.size.equalTo(Layout.emotionOrbImageViewSize) |
| 79 | + } |
| 80 | + |
| 81 | + registerEmotionLabel.snp.makeConstraints { make in |
| 82 | + make.leading.equalTo(emotionOrbImageView.snp.trailing).offset(Layout.registerEmotionLabelLeadingSpacing) |
| 83 | + make.centerY.equalToSuperview() |
| 84 | + } |
| 85 | + |
| 86 | + registerEmotionButton.snp.makeConstraints { make in |
| 87 | + make.trailing.equalToSuperview().inset(Layout.registerEmotionButtonTrailingSpacing) |
| 88 | + make.centerY.equalToSuperview() |
| 89 | + make.width.equalTo(Layout.registerEmotionButtonWidth) |
| 90 | + make.height.equalTo(Layout.registerEmotionButtonHeight) |
| 91 | + } |
| 92 | + } |
| 93 | +} |
0 commit comments