-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#171: 라디오버튼 + 타이틀 컴포넌트 > RadioButtonView 생성
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// RadioButtonView.swift | ||
// Zatch | ||
// | ||
// Created by 박소윤 on 2023/02/10. | ||
// | ||
|
||
import Foundation | ||
|
||
extension ZatchComponent{ | ||
|
||
class RadioButtonView: BaseView{ | ||
|
||
var isSelected = false{ | ||
didSet{ | ||
radioButton.isSelected = isSelected | ||
self.tag = isSelected ? Const.ViewTag.select : Const.ViewTag.unselect | ||
} | ||
} | ||
|
||
private let stackView = UIStackView().then{ | ||
$0.isUserInteractionEnabled = true | ||
$0.spacing = 8 | ||
$0.axis = .horizontal | ||
} | ||
|
||
private lazy var radioButton = UIButton().then{ | ||
$0.isUserInteractionEnabled = false | ||
$0.setImage(Image.zatchUncheck, for: .normal) | ||
$0.setImage(Image.zatchCheck, for: .selected) | ||
} | ||
|
||
private let titleLabel = UILabel().then{ | ||
$0.setTypoStyleWithSingleLine(typoStyle: .medium14) | ||
$0.textColor = .black85 | ||
} | ||
|
||
override func hierarchy() { | ||
self.addSubview(stackView) | ||
stackView.addArrangedSubview(radioButton) | ||
stackView.addArrangedSubview(titleLabel) | ||
} | ||
|
||
override func layout() { | ||
stackView.snp.makeConstraints{ | ||
$0.top.leading.trailing.bottom.equalToSuperview() | ||
} | ||
radioButton.snp.makeConstraints{ | ||
$0.width.height.equalTo(24) | ||
} | ||
} | ||
|
||
func setTitle(_ title: String){ | ||
titleLabel.text = title | ||
} | ||
} | ||
} |