Skip to content

Commit

Permalink
[Refactor] TeamSparker#571 - SendSparkButton 이니셜라이저를 활용한 초기화로 리펙토링
Browse files Browse the repository at this point in the history
- 불필요한 오버라이드하던 생성자 삭제.
- UI 가 변경되면서 사용하지 않던 isSelected 삭제.
- didset property observer 를 통해서 content 설정
  • Loading branch information
hyun99999 committed May 9, 2022
1 parent 722b21f commit a45dcc3
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions Spark-iOS/Spark-iOS/Source/Classes/SendSparkButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ final class SendSparkButton: UIButton {

// MARK: - Properties

var type: SendSparkStatus?
var type: SendSparkStatus {
didSet {
self.setContent()
}
}
var content: String?

// MARK: - Initialize

override init(frame: CGRect) {
super.init(frame: frame)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

public init(type: SendSparkStatus) {
init(type: SendSparkStatus) {
self.type = type
super.init(frame: .zero)

setUI(type)
setUI(self.type)
}
}

Expand All @@ -53,8 +53,10 @@ extension SendSparkButton {
self.titleLabel?.lineBreakMode = .byCharWrapping
self.titleLabel?.textAlignment = .center
self.type = type

switch type {
}

private func setContent() {
switch self.type {
case .message:
self.setTitle("""
메시지
Expand Down Expand Up @@ -97,18 +99,4 @@ extension SendSparkButton {
self.content = "👍얼마 안 남았어, 어서 하자!"
}
}

public func isSelected(_ isSelected: Bool) {
if isSelected {
self.setTitleColor(.sparkDarkPinkred, for: .normal)
self.backgroundColor = .sparkMostLightPinkred
self.titleLabel?.backgroundColor = .sparkMostLightPinkred
self.layer.borderColor = UIColor.sparkDarkPinkred.cgColor
} else {
self.setTitleColor(.sparkLightPinkred, for: .normal)
self.backgroundColor = .sparkWhite
self.titleLabel?.backgroundColor = .sparkWhite
self.layer.borderColor = UIColor.sparkLightPinkred.cgColor
}
}
}

0 comments on commit a45dcc3

Please sign in to comment.