From 167a7ac8b1cb5298443b2989aac47a846ba7a12d Mon Sep 17 00:00:00 2001 From: hyeonju Date: Wed, 7 Aug 2024 15:39:54 +0900 Subject: [PATCH] =?UTF-8?q?[#6]=20checkBox,=20radioButton=20tintColor=20?= =?UTF-8?q?=EC=BB=A4=EC=8A=A4=ED=85=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Atom/CheckBoxViewController.swift | 1 + .../Atom/RadioButtonViewController.swift | 2 + Handy/Handy/Source/Atom/HandyCheckBox.swift | 59 +++++++++++++---- .../Handy/Source/Atom/HandyRadioButton.swift | 63 ++++++++++++++----- .../checkBoxFilled.svg | 4 -- .../Contents.json | 0 .../checkBoxFilled.svg | 3 + .../Contents.json | 0 .../checkBoxLine.imageset/checkBoxLine.svg | 4 ++ .../checkBoxSelected.imageset/Contents.json | 12 ---- .../checkBoxSelected.svg | 4 -- .../checkBoxLine.svg | 5 -- .../Contents.json | 2 +- ...tonDisabled.svg => RadioButtonDisable.svg} | 1 - .../Contents.json | 0 .../radioButtonUnselcted.svg | 0 .../Contents.json | 12 ---- .../radioButtonSelected.svg | 4 -- Handy/Handy/Source/Foundation/HandyIcon.swift | 8 +-- 19 files changed, 109 insertions(+), 75 deletions(-) delete mode 100644 Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxDisabled.imageset/checkBoxFilled.svg rename Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/{checkBoxDisabled.imageset => checkBoxFilled.imageset}/Contents.json (100%) create mode 100644 Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxFilled.imageset/checkBoxFilled.svg rename Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/{checkBoxUnSelected.imageset => checkBoxLine.imageset}/Contents.json (100%) create mode 100644 Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxLine.imageset/checkBoxLine.svg delete mode 100644 Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxSelected.imageset/Contents.json delete mode 100644 Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxSelected.imageset/checkBoxSelected.svg delete mode 100644 Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxUnSelected.imageset/checkBoxLine.svg rename Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonDisabled.imageset/{radioButtonDisabled.svg => RadioButtonDisable.svg} (75%) rename Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/{radioButtonUnselected.imageset => radioButtonLine.imageset}/Contents.json (100%) rename Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/{radioButtonUnselected.imageset => radioButtonLine.imageset}/radioButtonUnselcted.svg (100%) delete mode 100644 Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonSelected.imageset/Contents.json delete mode 100644 Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonSelected.imageset/radioButtonSelected.svg diff --git a/Handy/Handy-Storybook/Atom/CheckBoxViewController.swift b/Handy/Handy-Storybook/Atom/CheckBoxViewController.swift index 23b1474..51ff0f4 100644 --- a/Handy/Handy-Storybook/Atom/CheckBoxViewController.swift +++ b/Handy/Handy-Storybook/Atom/CheckBoxViewController.swift @@ -11,6 +11,7 @@ final class CheckBoxViewController: BaseViewController { let checkBox: HandyCheckBox = { let checkBox = HandyCheckBox() + checkBox.setTintColor = .red return checkBox }() diff --git a/Handy/Handy-Storybook/Atom/RadioButtonViewController.swift b/Handy/Handy-Storybook/Atom/RadioButtonViewController.swift index 821d402..e5355c1 100644 --- a/Handy/Handy-Storybook/Atom/RadioButtonViewController.swift +++ b/Handy/Handy-Storybook/Atom/RadioButtonViewController.swift @@ -11,6 +11,7 @@ final class RadioButtonViewController: BaseViewController { let radioButton: HandyRadioButton = { let checkBox = HandyRadioButton() + checkBox.isSelected = true return checkBox }() @@ -23,6 +24,7 @@ final class RadioButtonViewController: BaseViewController { let disabledRadioButton: HandyRadioButton = { let checkBox = HandyRadioButton() checkBox.isDisabled = true + checkBox.text = "RadioButton" return checkBox }() diff --git a/Handy/Handy/Source/Atom/HandyCheckBox.swift b/Handy/Handy/Source/Atom/HandyCheckBox.swift index 6ac3395..7b85afe 100644 --- a/Handy/Handy/Source/Atom/HandyCheckBox.swift +++ b/Handy/Handy/Source/Atom/HandyCheckBox.swift @@ -45,6 +45,15 @@ public class HandyCheckBox: UIButton { } } + /** + 체크박스의 tintColor를 설정할 때 사용합니다. + */ + public var setTintColor: UIColor = HandySemantic.checkboxSelected { + didSet { + setConfiguration() + } + } + // MARK: - 외부에서 접근할 수 있는 enum /** @@ -94,34 +103,62 @@ public class HandyCheckBox: UIButton { private func setConfiguration() { var configuration = UIButton.Configuration.plain() configuration.baseBackgroundColor = .clear + configuration.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0) + self.configuration = configuration + + setTitle() + setImage() + setColor() + updateState() + } + private func setTitle() { + guard var configuration = self.configuration else { return } configuration.attributedTitle = AttributedString(text ?? "") configuration.attributedTitle?.font = size.font + self.configuration = configuration + } + + private func setImage() { + guard var configuration = self.configuration else { return } configuration.imagePadding = 8 configuration.imagePlacement = .leading - configuration.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0) + let image: UIImage + if isDisabled || isSelected { + image = HandyIcon.checkBoxFilled + } else { + image = HandyIcon.checkBoxLine + } + configuration.image = image.resize(to: size.iconSize) + + self.configuration = configuration + } - switch (isDisabled, isSelected) { - case (true, _): - configuration.image = HandyIcon.checkBoxDisabled.resize(to: size.iconSize) - configuration.baseBackgroundColor = HandySemantic.textBasicPrimary - case (false, true): - configuration.image = HandyIcon.checkBoxSelected.resize(to: size.iconSize) - configuration.baseForegroundColor = HandySemantic.textBasicPrimary + private func setColor() { + guard var configuration = self.configuration else { return } - case (false, false): - configuration.image = HandyIcon.checkBoxUnSelected.resize(to: size.iconSize) - configuration.baseForegroundColor = HandySemantic.textBasicPrimary + if isSelected { + configuration.image = configuration.image?.withTintColor(setTintColor) } + + self.configuration = configuration + } + + + private func updateState() { + guard var configuration = self.configuration else { return } + + configuration.baseForegroundColor = HandySemantic.textBasicPrimary self.isEnabled = !isDisabled self.configuration = configuration } + private func registerTapAction() { self.addTarget(self, action: #selector(checkboxDidTap(_:)), diff --git a/Handy/Handy/Source/Atom/HandyRadioButton.swift b/Handy/Handy/Source/Atom/HandyRadioButton.swift index 712e492..e32b786 100644 --- a/Handy/Handy/Source/Atom/HandyRadioButton.swift +++ b/Handy/Handy/Source/Atom/HandyRadioButton.swift @@ -45,6 +45,15 @@ public class HandyRadioButton: UIButton { } } + /** + 라디오버튼의 tintColor를 설정할 때 사용합니다. + */ + public var setTintColor: UIColor = HandySemantic.checkboxSelected { + didSet { + setConfiguration() + } + } + // MARK: - 외부에서 접근할 수 있는 enum /** @@ -94,44 +103,66 @@ public class HandyRadioButton: UIButton { private func setConfiguration() { var configuration = UIButton.Configuration.plain() configuration.baseBackgroundColor = .clear + configuration.imagePadding = 8 + configuration.imagePlacement = .leading + configuration.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0) + self.configuration = configuration + setTitle() + setImage() + setColor() + updateState() + } + + private func setTitle() { + guard var configuration = self.configuration else { return } configuration.attributedTitle = AttributedString(text ?? "") configuration.attributedTitle?.font = size.font + self.configuration = configuration + } - configuration.imagePadding = 8 - configuration.imagePlacement = .leading - - configuration.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0) + private func setImage() { + guard var configuration = self.configuration else { return } - switch (isDisabled, isSelected) { - case (true, _): + if isDisabled { configuration.image = HandyIcon.radioButtonDisabled.resize(to: size.iconSize) - configuration.baseBackgroundColor = HandySemantic.textBasicPrimary + } else { + configuration.image = HandyIcon.radioButtonLine.resize(to: size.iconSize) + } + + self.configuration = configuration + } - case (false, true): - configuration.image = HandyIcon.radioButtonSelected.resize(to: size.iconSize) - configuration.baseForegroundColor = HandySemantic.textBasicPrimary + private func setColor() { + guard var configuration = self.configuration else { return } - case (false, false): - configuration.image = HandyIcon.radioButtonUnselected.resize(to: size.iconSize) - configuration.baseForegroundColor = HandySemantic.textBasicPrimary + if isSelected { + configuration.image = configuration.image?.withTintColor(setTintColor) } + self.configuration = configuration + } + + + private func updateState() { + guard var configuration = self.configuration else { return } + + configuration.baseForegroundColor = HandySemantic.textBasicPrimary self.isEnabled = !isDisabled self.configuration = configuration } + private func registerTapAction() { self.addTarget(self, - action: #selector(checkboxDidTap(_:)), + action: #selector(radioButtonDidtap(_:)), for: .touchUpInside ) } @objc - private func checkboxDidTap(_ sender: UIControl) { + private func radioButtonDidtap(_ sender: UIControl) { self.isSelected = !isSelected } } - diff --git a/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxDisabled.imageset/checkBoxFilled.svg b/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxDisabled.imageset/checkBoxFilled.svg deleted file mode 100644 index 8763607..0000000 --- a/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxDisabled.imageset/checkBoxFilled.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxDisabled.imageset/Contents.json b/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxFilled.imageset/Contents.json similarity index 100% rename from Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxDisabled.imageset/Contents.json rename to Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxFilled.imageset/Contents.json diff --git a/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxFilled.imageset/checkBoxFilled.svg b/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxFilled.imageset/checkBoxFilled.svg new file mode 100644 index 0000000..baa7a49 --- /dev/null +++ b/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxFilled.imageset/checkBoxFilled.svg @@ -0,0 +1,3 @@ + + + diff --git a/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxUnSelected.imageset/Contents.json b/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxLine.imageset/Contents.json similarity index 100% rename from Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxUnSelected.imageset/Contents.json rename to Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxLine.imageset/Contents.json diff --git a/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxLine.imageset/checkBoxLine.svg b/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxLine.imageset/checkBoxLine.svg new file mode 100644 index 0000000..76f27e1 --- /dev/null +++ b/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxLine.imageset/checkBoxLine.svg @@ -0,0 +1,4 @@ + + + + diff --git a/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxSelected.imageset/Contents.json b/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxSelected.imageset/Contents.json deleted file mode 100644 index 32fb19f..0000000 --- a/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxSelected.imageset/Contents.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "images" : [ - { - "filename" : "checkBoxSelected.svg", - "idiom" : "universal" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxSelected.imageset/checkBoxSelected.svg b/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxSelected.imageset/checkBoxSelected.svg deleted file mode 100644 index 87acab6..0000000 --- a/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxSelected.imageset/checkBoxSelected.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxUnSelected.imageset/checkBoxLine.svg b/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxUnSelected.imageset/checkBoxLine.svg deleted file mode 100644 index a8854ee..0000000 --- a/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/checkBox/checkBoxUnSelected.imageset/checkBoxLine.svg +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonDisabled.imageset/Contents.json b/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonDisabled.imageset/Contents.json index 0166121..9938e8d 100644 --- a/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonDisabled.imageset/Contents.json +++ b/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonDisabled.imageset/Contents.json @@ -1,7 +1,7 @@ { "images" : [ { - "filename" : "radioButtonDisabled.svg", + "filename" : "RadioButtonDisable.svg", "idiom" : "universal" } ], diff --git a/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonDisabled.imageset/radioButtonDisabled.svg b/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonDisabled.imageset/RadioButtonDisable.svg similarity index 75% rename from Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonDisabled.imageset/radioButtonDisabled.svg rename to Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonDisabled.imageset/RadioButtonDisable.svg index 8d290c5..5dd7cc8 100644 --- a/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonDisabled.imageset/radioButtonDisabled.svg +++ b/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonDisabled.imageset/RadioButtonDisable.svg @@ -1,4 +1,3 @@ - diff --git a/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonUnselected.imageset/Contents.json b/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonLine.imageset/Contents.json similarity index 100% rename from Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonUnselected.imageset/Contents.json rename to Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonLine.imageset/Contents.json diff --git a/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonUnselected.imageset/radioButtonUnselcted.svg b/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonLine.imageset/radioButtonUnselcted.svg similarity index 100% rename from Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonUnselected.imageset/radioButtonUnselcted.svg rename to Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonLine.imageset/radioButtonUnselcted.svg diff --git a/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonSelected.imageset/Contents.json b/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonSelected.imageset/Contents.json deleted file mode 100644 index 85fdab9..0000000 --- a/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonSelected.imageset/Contents.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "images" : [ - { - "filename" : "radioButtonSelected.svg", - "idiom" : "universal" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonSelected.imageset/radioButtonSelected.svg b/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonSelected.imageset/radioButtonSelected.svg deleted file mode 100644 index 1b096f5..0000000 --- a/Handy/Handy/Source/Foundation/Asset/HandyIcon.xcassets/radioButton/radioButtonSelected.imageset/radioButtonSelected.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/Handy/Handy/Source/Foundation/HandyIcon.swift b/Handy/Handy/Source/Foundation/HandyIcon.swift index 23c92dc..345ad68 100644 --- a/Handy/Handy/Source/Foundation/HandyIcon.swift +++ b/Handy/Handy/Source/Foundation/HandyIcon.swift @@ -11,11 +11,9 @@ public enum HandyIcon { public static var icCancelFilled: UIImage { .load(name: "icCancelFilled") } public static var icCancelLine: UIImage { .load(name: "icCancelLine") } - public static var checkBoxUnSelected: UIImage { .load(name: "checkBoxUnSelected") } - public static var checkBoxSelected: UIImage { .load(name: "checkBoxSelected") } - public static var checkBoxDisabled: UIImage { .load(name: "checkBoxDisabled") } - public static var radioButtonUnselected: UIImage { .load(name: "radioButtonUnselected") } - public static var radioButtonSelected: UIImage { .load(name: "radioButtonSelected") } + public static var checkBoxFilled: UIImage { .load(name: "checkBoxFilled") } + public static var checkBoxLine: UIImage { .load(name: "checkBoxLine") } + public static var radioButtonLine: UIImage { .load(name: "radioButtonLine") } public static var radioButtonDisabled: UIImage { .load(name: "radioButtonDisabled") } }