From 71b7eb5e219749bbe19b20fccd0c63a60096ca4d Mon Sep 17 00:00:00 2001 From: Johyeon Yoon Date: Thu, 9 Nov 2023 16:13:13 +0900 Subject: [PATCH] =?UTF-8?q?DealiSwitch=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project.pbxproj | 32 +++- .../ViewControllers/MainViewController.swift | 81 ++++---- .../{ => Sub}/AlertTestViewController.swift | 0 .../BottomSheetViewController.swift} | 6 +- .../{ => Sub}/ButtonViewController.swift | 0 .../{ => Sub}/ChipViewController.swift | 0 .../{ => Sub}/ColorViewController.swift | 0 .../{ => Sub}/RadioButtonViewController.swift | 0 .../Sub/SwitchViewController.swift | 59 ++++++ .../{ => Sub}/TypographyViewController.swift | 0 .../Components/Switch/DealiSwitch.swift | 173 ++++++++++++++++++ 11 files changed, 305 insertions(+), 46 deletions(-) rename DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/{ => Sub}/AlertTestViewController.swift (100%) rename DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/{File.swift => Sub/BottomSheetViewController.swift} (89%) rename DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/{ => Sub}/ButtonViewController.swift (100%) rename DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/{ => Sub}/ChipViewController.swift (100%) rename DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/{ => Sub}/ColorViewController.swift (100%) rename DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/{ => Sub}/RadioButtonViewController.swift (100%) create mode 100644 DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/Sub/SwitchViewController.swift rename DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/{ => Sub}/TypographyViewController.swift (100%) create mode 100644 Sources/DealiDesignKit/Components/Switch/DealiSwitch.swift diff --git a/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp.xcodeproj/project.pbxproj b/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp.xcodeproj/project.pbxproj index cd5efefe..7b5602ee 100644 --- a/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp.xcodeproj/project.pbxproj +++ b/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp.xcodeproj/project.pbxproj @@ -19,8 +19,9 @@ 042EA8C12A15AD5200370706 /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 042EA8C02A15AD5200370706 /* MainView.swift */; }; 04AD45132A15EF4400093BEB /* TypographyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04AD45122A15EF4400093BEB /* TypographyViewController.swift */; }; 04AD45152A15EF5900093BEB /* TypographyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04AD45142A15EF5900093BEB /* TypographyView.swift */; }; + 4D1FA9292AFC778E00AA510F /* SwitchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D1FA9282AFC778E00AA510F /* SwitchViewController.swift */; }; 4D5326D52AB15FFF00A9509A /* ButtonViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D5326D42AB15FFF00A9509A /* ButtonViewController.swift */; }; - 4DB2D6F42AFB281100DFF053 /* File.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DB2D6F32AFB281100DFF053 /* File.swift */; }; + 4DB2D6F42AFB281100DFF053 /* BottomSheetViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DB2D6F32AFB281100DFF053 /* BottomSheetViewController.swift */; }; 5A1E6B7D2AE68B270048D751 /* ChipViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A1E6B7C2AE68B270048D751 /* ChipViewController.swift */; }; E6EA11A42A8A24DC00ACCF3B /* AlertTestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6EA11A32A8A24DC00ACCF3B /* AlertTestViewController.swift */; }; FC52E5FF2AA0315B00CADB39 /* RadioButtonViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC52E5FE2AA0315B00CADB39 /* RadioButtonViewController.swift */; }; @@ -39,8 +40,9 @@ 042EA8C02A15AD5200370706 /* MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainView.swift; sourceTree = ""; }; 04AD45122A15EF4400093BEB /* TypographyViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypographyViewController.swift; sourceTree = ""; }; 04AD45142A15EF5900093BEB /* TypographyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypographyView.swift; sourceTree = ""; }; + 4D1FA9282AFC778E00AA510F /* SwitchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwitchViewController.swift; sourceTree = ""; }; 4D5326D42AB15FFF00A9509A /* ButtonViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonViewController.swift; sourceTree = ""; }; - 4DB2D6F32AFB281100DFF053 /* File.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = File.swift; sourceTree = ""; }; + 4DB2D6F32AFB281100DFF053 /* BottomSheetViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BottomSheetViewController.swift; sourceTree = ""; }; 5A1E6B7C2AE68B270048D751 /* ChipViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChipViewController.swift; sourceTree = ""; }; E6EA11A32A8A24DC00ACCF3B /* AlertTestViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertTestViewController.swift; sourceTree = ""; }; FC52E5FE2AA0315B00CADB39 /* RadioButtonViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioButtonViewController.swift; sourceTree = ""; }; @@ -101,14 +103,8 @@ 04AD450F2A15EEF900093BEB /* ViewControllers */ = { isa = PBXGroup; children = ( - 4DB2D6F32AFB281100DFF053 /* File.swift */, - FC52E5FE2AA0315B00CADB39 /* RadioButtonViewController.swift */, 042EA8AC2A14C7D500370706 /* MainViewController.swift */, - 04AD45122A15EF4400093BEB /* TypographyViewController.swift */, - 041ABC0B2A175E19001772F3 /* ColorViewController.swift */, - E6EA11A32A8A24DC00ACCF3B /* AlertTestViewController.swift */, - 4D5326D42AB15FFF00A9509A /* ButtonViewController.swift */, - 5A1E6B7C2AE68B270048D751 /* ChipViewController.swift */, + 4D1FA9272AFC740000AA510F /* Sub */, ); path = ViewControllers; sourceTree = ""; @@ -133,6 +129,21 @@ path = Others; sourceTree = ""; }; + 4D1FA9272AFC740000AA510F /* Sub */ = { + isa = PBXGroup; + children = ( + 5A1E6B7C2AE68B270048D751 /* ChipViewController.swift */, + 4D5326D42AB15FFF00A9509A /* ButtonViewController.swift */, + E6EA11A32A8A24DC00ACCF3B /* AlertTestViewController.swift */, + 041ABC0B2A175E19001772F3 /* ColorViewController.swift */, + 04AD45122A15EF4400093BEB /* TypographyViewController.swift */, + FC52E5FE2AA0315B00CADB39 /* RadioButtonViewController.swift */, + 4DB2D6F32AFB281100DFF053 /* BottomSheetViewController.swift */, + 4D1FA9282AFC778E00AA510F /* SwitchViewController.swift */, + ); + path = Sub; + sourceTree = ""; + }; FCEC04882A72B9A60004E5DB /* Packages */ = { isa = PBXGroup; children = ( @@ -222,7 +233,7 @@ buildActionMask = 2147483647; files = ( 042EA8AD2A14C7D500370706 /* MainViewController.swift in Sources */, - 4DB2D6F42AFB281100DFF053 /* File.swift in Sources */, + 4DB2D6F42AFB281100DFF053 /* BottomSheetViewController.swift in Sources */, 04AD45132A15EF4400093BEB /* TypographyViewController.swift in Sources */, 041ABC0C2A175E19001772F3 /* ColorViewController.swift in Sources */, E6EA11A42A8A24DC00ACCF3B /* AlertTestViewController.swift in Sources */, @@ -232,6 +243,7 @@ 5A1E6B7D2AE68B270048D751 /* ChipViewController.swift in Sources */, 042EA8AB2A14C7D500370706 /* SceneDelegate.swift in Sources */, 04AD45152A15EF5900093BEB /* TypographyView.swift in Sources */, + 4D1FA9292AFC778E00AA510F /* SwitchViewController.swift in Sources */, 4D5326D52AB15FFF00A9509A /* ButtonViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/MainViewController.swift b/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/MainViewController.swift index 43c5d395..f23543d0 100644 --- a/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/MainViewController.swift +++ b/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/MainViewController.swift @@ -21,48 +21,63 @@ final class MainViewController: UIViewController { self.navigationItem.backButtonTitle = "Home" self.title = "iOS Design System Sample App" - let alertButton = DealiButton() - self.view.addSubview(alertButton) - alertButton.then { - $0.style = .medium(style: .filled) - $0.title = "Alert" - $0.addTarget(self, action: #selector(alertButtonPressed), for: .touchUpInside) + let scrollView = UIScrollView() + self.view.addSubview(scrollView) + scrollView.snp.makeConstraints { + $0.edges.equalToSuperview() + } + + let contentView = UIView() + scrollView.addSubview(contentView) + contentView.snp.makeConstraints { + $0.edges.equalToSuperview() + $0.width.equalToSuperview() + } + + let contentStackView = UIStackView() + contentView.addSubview(contentStackView) + contentStackView.then { + $0.axis = .vertical + $0.spacing = 20.0 }.snp.makeConstraints { - $0.top.equalToSuperview().offset(100.0) + $0.top.equalToSuperview().inset(30.0) $0.left.right.equalToSuperview().inset(20.0) + $0.bottom.equalToSuperview() + } + + let alertButton = DealiControl.btnOutlineLargeSecondary01() + contentStackView.addArrangedSubview(alertButton) + alertButton.do { + $0.title = "Alert" + $0.addTarget(self, action: #selector(alertButtonPressed), for: .touchUpInside) } - let radioButton = DealiButton() - self.view.addSubview(radioButton) - radioButton.then { - $0.style = .medium(style: .filled) + let radioButton = DealiControl.btnOutlineLargeSecondary01() + contentStackView.addArrangedSubview(radioButton) + radioButton.do { $0.title = "RadioButton" $0.addTarget(self, action: #selector(radioButtonPressed), for: .touchUpInside) - }.snp.makeConstraints { - $0.top.equalTo(alertButton.snp.bottom).offset(20.0) - $0.left.right.equalToSuperview().inset(20.0) } - let buttonComponentsButton = DealiButton() - self.view.addSubview(buttonComponentsButton) - buttonComponentsButton.then { - $0.style = .medium(style: .filled) + let buttonComponentsButton = DealiControl.btnOutlineLargeSecondary01() + contentStackView.addArrangedSubview(buttonComponentsButton) + buttonComponentsButton.do { $0.title = "Button Components" $0.addTarget(self, action: #selector(buttonComponentButtonPressed), for: .touchUpInside) - }.snp.makeConstraints { - $0.top.equalTo(radioButton.snp.bottom).offset(20.0) - $0.left.right.equalToSuperview().inset(20.0) } - let chipComponentsButton = DealiButton() - self.view.addSubview(chipComponentsButton) - chipComponentsButton.then { - $0.style = .medium(style: .filled) + let chipComponentsButton = DealiControl.btnOutlineLargeSecondary01() + contentStackView.addArrangedSubview(chipComponentsButton) + chipComponentsButton.do { $0.title = "Chip Components" $0.addTarget(self, action: #selector(chipButtonPressed), for: .touchUpInside) - }.snp.makeConstraints { - $0.top.equalTo(buttonComponentsButton.snp.bottom).offset(20.0) - $0.left.right.equalToSuperview().inset(20.0) + } + + let switchComponentButton = DealiControl.btnOutlineLargeSecondary01() + contentStackView.addArrangedSubview(switchComponentButton) + switchComponentButton.do { + $0.title = "Toggle/Switch" + $0.addTarget(self, action: #selector(toggleButtonPressed), for: .touchUpInside) } } @@ -97,10 +112,10 @@ extension MainViewController { } @objc func chipButtonPressed() { -// self.navigationController?.pushViewController(ChipViewController(), animated: true) - let vc = MyViewController() - vc.modalTransitionStyle = .crossDissolve - vc.modalPresentationStyle = .overCurrentContext - self.present(vc, animated: true) + self.navigationController?.pushViewController(ChipViewController(), animated: true) + } + + @objc func toggleButtonPressed() { + self.navigationController?.pushViewController(SwitchViewController(), animated: true) } } diff --git a/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/AlertTestViewController.swift b/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/Sub/AlertTestViewController.swift similarity index 100% rename from DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/AlertTestViewController.swift rename to DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/Sub/AlertTestViewController.swift diff --git a/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/File.swift b/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/Sub/BottomSheetViewController.swift similarity index 89% rename from DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/File.swift rename to DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/Sub/BottomSheetViewController.swift index ccf29900..b528f461 100644 --- a/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/File.swift +++ b/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/Sub/BottomSheetViewController.swift @@ -1,6 +1,6 @@ // -// File.swift -// +// BottomSheetViewController.swift +// // // Created by JohyeonYoon on 11/6/23. // @@ -8,7 +8,7 @@ import UIKit import DealiDesignKit -class MyViewController: DealiBottomSheetViewController { +class BottomSheetViewController: DealiBottomSheetViewController { override func loadView() { super.loadView() diff --git a/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/ButtonViewController.swift b/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/Sub/ButtonViewController.swift similarity index 100% rename from DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/ButtonViewController.swift rename to DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/Sub/ButtonViewController.swift diff --git a/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/ChipViewController.swift b/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/Sub/ChipViewController.swift similarity index 100% rename from DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/ChipViewController.swift rename to DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/Sub/ChipViewController.swift diff --git a/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/ColorViewController.swift b/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/Sub/ColorViewController.swift similarity index 100% rename from DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/ColorViewController.swift rename to DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/Sub/ColorViewController.swift diff --git a/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/RadioButtonViewController.swift b/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/Sub/RadioButtonViewController.swift similarity index 100% rename from DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/RadioButtonViewController.swift rename to DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/Sub/RadioButtonViewController.swift diff --git a/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/Sub/SwitchViewController.swift b/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/Sub/SwitchViewController.swift new file mode 100644 index 00000000..4611bf4f --- /dev/null +++ b/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/Sub/SwitchViewController.swift @@ -0,0 +1,59 @@ +// +// SwitchViewController.swift +// DealiDesignSystemSampleApp +// +// Created by 윤조현 on 2023/11/09. +// Copyright © 2023 Dealicious Inc. All rights reserved. +// + +import UIKit +import DealiDesignKit + +final class SwitchViewController: UIViewController { + let enableSwitch = DealiSwitch() + + override func loadView() { + self.view = .init() + + self.view.backgroundColor = .systemBackground + + self.view.addSubview(enableSwitch) + enableSwitch.style = .iosSystem + enableSwitch.addTarget(self, action: #selector(systemSwitchValueChanged), for: .valueChanged) + enableSwitch.snp.makeConstraints { + $0.center.equalToSuperview() + } + + let disableOffSwitch = DealiSwitch() + self.view.addSubview(disableOffSwitch) + disableOffSwitch.then { + $0.isEnabled = false + }.snp.makeConstraints { + $0.centerX.equalToSuperview() + $0.top.equalTo(enableSwitch.snp.bottom).offset(20.0) + } + + + let disableOnSwitch = DealiSwitch(style: .andriodSystem) + self.view.addSubview(disableOnSwitch) + disableOnSwitch.then { + $0.setOn(false, animated: true) + }.snp.makeConstraints { + $0.centerX.equalToSuperview() + $0.top.equalTo(disableOffSwitch.snp.bottom).offset(20.0) + } + } + + override func viewDidLoad() { + super.viewDidLoad() + + + } + + @objc func systemSwitchValueChanged() { + print(self.enableSwitch.isOn) + } +} + + + diff --git a/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/TypographyViewController.swift b/DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/Sub/TypographyViewController.swift similarity index 100% rename from DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/TypographyViewController.swift rename to DealiDesignSystemSampleApp/DealiDesignSystemSampleApp/ViewControllers/Sub/TypographyViewController.swift diff --git a/Sources/DealiDesignKit/Components/Switch/DealiSwitch.swift b/Sources/DealiDesignKit/Components/Switch/DealiSwitch.swift new file mode 100644 index 00000000..fdd1a700 --- /dev/null +++ b/Sources/DealiDesignKit/Components/Switch/DealiSwitch.swift @@ -0,0 +1,173 @@ +// +// DealiSwitch.swift +// +// +// Created by 윤조현 on 2023/11/09. +// + +import UIKit + +/// +/// Toggle/Switch Component +/// +/// +/// +public class DealiSwitch: UIControl { + + public enum SwitchStyle { + /// 시스템 UISwitch 처럼 생긴 형태. default 값 + case iosSystem + case andriodSystem + } + + public var style: SwitchStyle = .iosSystem { + didSet { + self.setupViews() + } + } + + private var backgroundView = UIView() + private var thumbView = UIView() + public var isOn = false + + public convenience init(style: SwitchStyle = .iosSystem) { + self.init(frame: .zero) + + self.style = style + self.setupViews() + } + + // 커스텀 스위치의 초기 설정 + override init(frame: CGRect) { + super.init(frame: frame) + self.setupViews() + } + + required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + self.setupViews() + } + + // 뷰 및 레이아웃 설정 + private func setupViews() { + self.backgroundView.removeFromSuperview() + self.thumbView.removeFromSuperview() + + self.backgroundView = UIView() + self.thumbView = UIView() + + // 탭 제스처 + let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.switchTapped)) + self.addGestureRecognizer(tapGesture) + + if self.style == .iosSystem { + + // 배경 뷰 설정 + self.addSubview(self.backgroundView) + + self.backgroundView.then { + $0.backgroundColor = DealiColor.g30 + $0.clipsToBounds = true + $0.layer.cornerRadius = 15.0 + }.snp.makeConstraints { + $0.height.equalTo(30.0) + $0.width.equalTo(50.0) + $0.edges.equalToSuperview() + } + + // 썸 뷰(스위치의 움직이는 부분) 설정 + self.addSubview(self.thumbView) + self.thumbView.then { + $0.backgroundColor = DealiColor.primary04 + $0.layer.cornerRadius = 13.0 + $0.layer.masksToBounds = false + $0.layer.shadowColor = UIColor.black.cgColor + $0.layer.shadowOffset = CGSize(width: 0, height: 1) + $0.layer.shadowOpacity = 0.22 + + }.snp.makeConstraints { + $0.width.height.equalTo(26.0) + $0.top.bottom.left.equalToSuperview().inset(2.0) + } + + } else { + // 배경 뷰 설정 + self.addSubview(self.backgroundView) + + self.backgroundView.then { + $0.backgroundColor = DealiColor.g30 + $0.clipsToBounds = true + $0.layer.cornerRadius = 7.0 + }.snp.makeConstraints { + $0.left.right.centerY.equalToSuperview() + $0.top.bottom.equalToSuperview().inset(3.0) + $0.height.equalTo(14.0) + $0.width.equalTo(34.0) + } + + // 썸 뷰(스위치의 움직이는 부분) 설정 + self.addSubview(self.thumbView) + self.thumbView.then { + $0.backgroundColor = DealiColor.primary04 + $0.layer.cornerRadius = 10.0 + $0.layer.masksToBounds = false + $0.layer.shadowColor = UIColor.black.cgColor + $0.layer.shadowOffset = CGSize(width: 0, height: 1) + $0.layer.shadowOpacity = 0.22 + + }.snp.makeConstraints { + $0.width.height.equalTo(20.0) + $0.top.bottom.left.equalToSuperview() + } + } + + } + + // 스위치의 On/Off 상태를 토글하는 메서드 + @objc private func switchTapped() { + self.setOn(!isOn, animated: true) + self.sendActions(for: .valueChanged) + + } + + // 스위치의 On/Off 상태를 설정하는 메서드 + public func setOn(_ on: Bool, animated: Bool) { + self.isOn = on + if self.style == .iosSystem { + + let targetX = on ? bounds.width - thumbView.bounds.width - 2 : 2 + let backgroundColor = on ? DealiColor.primary01 : DealiColor.g30 + + if animated { + UIView.animate(withDuration: 0.3) { + self.thumbView.frame.origin.x = targetX + self.backgroundView.backgroundColor = backgroundColor + } + } else { + self.thumbView.frame.origin.x = targetX + self.backgroundView.backgroundColor = backgroundColor + } + + } else { + + let targetX = on ? bounds.width - thumbView.bounds.width : 0 + let thumbViewColor = on ? DealiColor.primary01 : DealiColor.primary04 + let backgroundColor = on ? DealiColor.primary03 : DealiColor.g30 + + if animated { + UIView.animate(withDuration: 0.3) { + self.thumbView.frame.origin.x = targetX + self.thumbView.backgroundColor = thumbViewColor + self.backgroundView.backgroundColor = backgroundColor + } + } else { + self.thumbView.frame.origin.x = targetX + self.thumbView.backgroundColor = thumbViewColor + self.backgroundView.backgroundColor = backgroundColor + + + } + } + + } +}