Skip to content

Conversation

@jaminleee
Copy link
Collaborator

๐Ÿ”ฅ Issue

close #


๐Ÿ”ฅ ๋ณ€๊ฒฝ๋œ ๋‚ด์šฉ

expand๋Š” ๋„ˆ๋น„๊ฐ€ ํ† ๊ธ€๋˜๋ฉด์„œ ๋ฐ”๋€Œ๋Š” ๋…€์„, normal์€ ํ‰๋ฒ”ํ•œ ์บก์А ๋ฒ„ํŠผ
UIImage(systemName: "plus") ์ด ๋ถ€๋ถ„๋„ defaultTitle๊ณผ ๊ฐ™์ด ์ดˆ๊ธฐํ™” ๋•Œ ๋ฐ›์€ ์•„์ด์ฝ˜์œผ๋กœ ํ† ๊ธ€๋˜๊ฒŒ ๋ฐ”๊ฟ”์ค˜์•ผํ•˜๋Š”๋ฐ ์ผ๋‹จ ๋” ์ˆ˜์ •ํ•˜๊ฒ ์Œ..
๋จธ๋ฆฌ๊ฐ€ ์ž˜ ์•ˆ๋Œ์•„๊ฐ€์„œ ๋งŽ์€ ํ”ผ๋“œ๋ฐฑ ๋ถ€ํƒ......ใ…œใ…œ
๋‹ค ํ•œ๊ฑฐ ์•„๋‹ˆ๊ณ  ๋‚ผ ๋” ์ถ”๊ฐ€ํ•˜๊ฒ ์‚ผ ใ… ใ… 

๐Ÿ”ฅ PR Point

// CapsuleButton
    private func updateButton(isExpanded: Bool) {
        let title = isExpanded ? "" : defaultTitle
        let icon = isExpanded ? UIImage(systemName: "xmark") : UIImage(systemName: "plus")
        configure(title: title, icon: icon)
        
        self.backgroundColor = isExpanded ? .appBlue50 : .appBlack
        self.setTitleColor(isExpanded ? .appBlack : .appWhite, for: .normal)
        self.tintColor = isExpanded ? .appBlack : .appWhite
        
        let newWidth = isExpanded ? 50 : 100
        self.widthConstraint?.update(offset: newWidth)
        UIView.animate(withDuration: 0.3) {
            self.superview?.layoutIfNeeded()
        }
    }
    
    // MARK: - Actions
    @objc private func buttonTapped() {
        switch capsuleButtonType {
        case .expand(let isExpanded):
            let newState = !isExpanded
            capsuleButtonType = .expand(isExpanded: newState)
            updateButton(isExpanded: newState)
            action?()
        case .normal:
            action?()
        }
    }

์ด๋Ÿฐ์‹์œผ๋กœ ์‚ฌ์šฉ

        let groupButton = CapsuleButton(
            type: .expand(isExpanded: false),
            title: "๊ทธ๋ฃน์ถ”๊ฐ€",
            icon: UIImage(systemName: "plus")
        ) {
            print("๊ทธ๋ฃน ๋ฒ„ํŠผ์ด ๋ˆŒ๋ ธ์Šต๋‹ˆ๋‹ค.")
        }
        
        let appointmentButton = CapsuleButton(type: .normal, title: "์•ฝ์†์ถ”๊ฐ€", icon: UIImage(systemName: "plus")) {
            print("์•ฝ์† ๋ฒ„ํŠผ ๋ˆŒ๋ฆผ")
        }

๐Ÿ”ฅ ScreenShot

Simulator Screen Recording - iPhone 16 Pro - 2025-01-11 at 04 53 00


๐Ÿ”ฅ Reference


@jaminleee jaminleee added the Feat ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ ๊ตฌํ˜„ label Jan 10, 2025
@jaminleee jaminleee self-assigned this Jan 10, 2025

// MARK: - Initializer
init(type: CapsuleButtonType, title: String, icon: UIImage?, action: (() -> Void)? = nil) {
self.defaultTitle = title
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CapsuleType์ด ๋‘ ๊ฐœ๋ฐ–์— ์—†๋Š” ๊ฑฐ ๊ฐ™์€๋ฐ, ์—ฌ๊ธฐ์„œ title์„ ๋”ฐ๋กœ ๋ฐ›์ง€ ๋ง๊ณ  ๊ฐ case๋งˆ๋‹ค ๋ฒ„ํŠผ ํƒ€์ดํ‹€์„ ์ถ”๊ฐ€ํ•˜๋Š”๊ฑด ์–ด๋–ต๊ฐ€์š”?

super.init(frame: .zero)
setupUI()
configure(title: title, icon: icon)
addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rx ํ•œ์†์œผ๋กœ ๋Œ๋ ค์ฃผ์„ธ์š”

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹๋Œ๋ ค์ฃผ์„ธ์š”


private func updateButton(isExpanded: Bool) {
let title = isExpanded ? "" : defaultTitle
let icon = isExpanded ? UIImage(systemName: "xmark") : UIImage(systemName: "plus")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•„์ด์ฝ˜์€ ์•ž์— ic_ ๋ถ™์—ฌ์ฃผ์‚ผ

Comment on lines 65 to 67
private func updateWidth(isExpanded: Bool) {

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด๊ฑด ๋ญ”๊ฐ€์š”?

Comment on lines 80 to 82
UIView.animate(withDuration: 0.3) {
self.superview?.layoutIfNeeded()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด ์ฝ”๋“œ๋Š” ๋ญํ•˜๋Š” ์ฝ”๋“œ ์ธ๊ฐ€์š”??

Copy link
Collaborator

@FpRaArNkK FpRaArNkK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ณ ์ƒ ๋งŽ์œผ์…จ์Šต๋‹ˆ๋‹ค! ๋ช‡๊ฐ€์ง€ ์ˆ˜์ •์‚ฌํ•ญ์ด ๋ณด์ด๋Š”๋ฐ ์ด๋ฏธ ๋‹ค๋ฅธ๋ถ„๋“ค์ด ์ž˜ ๋‚จ๊ฒจ์ฃผ์…”์„œ ์ถ”๊ฐ€ ๋ฉ˜ํŠธ๋งŒ ์ž‘์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค. ์ฐธ๊ณ  ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค

super.init(frame: .zero)
setupUI()
configure(title: title, icon: icon)
addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹๋Œ๋ ค์ฃผ์„ธ์š”

Comment on lines 17 to 20
enum CapsuleButtonType {
case expand(isExpanded: Bool)
case normal
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nested Type์ธ ๊ฒฝ์šฐ
CapsuleButton.CapsuleButtonType ์œผ๋กœ ์ ‘๊ทผ๋˜๋‹ˆ
์ƒ์œ„ ํƒ€์ž…๊ณผ ๊ฒน์น˜๋Š” ๋„ค์ด๋ฐ์€ ์ง€์–‘ํ•˜์‹œ๋ฉด ์ข‹์Šต๋‹ˆ๋‹ค!

Comment on lines 44 to 54
private func setupUI() {
self.do {
$0.backgroundColor = .appBlack
$0.layer.cornerRadius = 25
}

self.snp.makeConstraints {
$0.height.equalTo(50)
self.widthConstraint = $0.width.equalTo(100).constraint
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํŒ€ ์ฝ”๋“œ ์ปจ๋ฒค์…˜ ๋งž์ถฐ์ฃผ์‹ญ์‡ผ!

let newState = !isExpanded
capsuleButtonType = .expand(isExpanded: newState)
updateButton(isExpanded: newState)
action?()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด๊ฑด ์–ด๋–ค ์˜๋„๋กœ ์ž‘์„ฑํ•˜์‹ ๊ฑธ๊นŒ์š”?

var icon: UIImage? {
switch self {
case .expand(let isExpanded):
return isExpanded ? UIImage(systemName: "xmark") : UIImage(systemName: "plus")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ทจํ–ฅ์ฐจ์ด๊ธด ํ•œ๋ฐ ์ €๋Š” ๋ณดํ†ต ์•„๋ž˜ ์ฒ˜๋Ÿผ ์‚ฌ์šฉ ํ•ฉ๋‹ˆ๋‹ค.!

return UIImage(systemName: isExpanded ? "xmark" : "plus")

private var widthConstraint: Constraint?

// MARK: - Initializer
init(style: Style, action: (() -> Void)? = nil) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UIKit์—์„œ๋Š” ์ƒ์„ฑ์ž์—์„œ ๋„ฃ๋Š” ๋ฐฉ์‹์—์„œ ๋ฉ”์„œ๋“œ ์ฒด์ด๋‹ ๋ฐฉ์‹์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”!

๊ทธ๋Ÿฌ๋ฉด ์•„๋ž˜์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

capsuleButton.action = { // ๋ฒ„ํŠผ ๋ˆ„๋ฅด๋ฉด ์ž‘๋™ํ•  ์ด๋ฒคํŠธ ๋„ฃ๊ธฐ }

์ถ”๊ฐ€๋กœ action์„ ์™ธ๋ถ€์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด์„œ private์—์„œ var๋กœ ํ•ด์ฃผ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feat ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ ๊ตฌํ˜„

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants