-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
βοΈ :: [#68] ν κΈ view μ ν
- Loading branch information
Showing
5 changed files
with
231 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
Projects/Modules/DSKit/Demo/Sources/DemoViewController/View/ToggleViewController.swift
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,29 @@ | ||
import UIKit | ||
import SnapKit | ||
import Then | ||
|
||
public class ToggleViewController: UIViewController { | ||
|
||
let toggleView = MaeumGaGymToggleView(width: 430.0, height: 793.0) | ||
|
||
public override func viewDidLoad() { | ||
super.viewDidLoad() | ||
view.backgroundColor = .white | ||
|
||
layout() | ||
} | ||
|
||
func layout() { | ||
[ | ||
toggleView | ||
].forEach { view.addSubview($0) } | ||
|
||
toggleView.snp.makeConstraints { | ||
$0.centerX.equalToSuperview() | ||
$0.top.equalToSuperview().offset(101.0) | ||
$0.width.equalTo(430.0) | ||
$0.height.equalTo(845.0) | ||
} | ||
|
||
} | ||
} |
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 |
---|---|---|
|
@@ -74,3 +74,4 @@ public class DesignSystemViewController: UITableViewController { | |
} | ||
} | ||
} | ||
|
60 changes: 60 additions & 0 deletions
60
...cts/Modules/DSKit/Sources/Components/MaeumGaGymButton/Toggle/MaeumGaGymToggleButton.swift
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,60 @@ | ||
import UIKit | ||
import Then | ||
import SnapKit | ||
import RxSwift | ||
import RxCocoa | ||
|
||
open class MaeumGaGymToggleButton: UIButton { | ||
|
||
public let disposeBag = DisposeBag() | ||
|
||
|
||
|
||
private let textLabel = UILabel().then { | ||
$0.textAlignment = .center | ||
$0.numberOfLines = 1 | ||
$0.font = UIFont.Pretendard.labelLarge | ||
$0.textColor = .black | ||
$0.backgroundColor = .clear | ||
} | ||
|
||
|
||
public init ( | ||
type: ToggleButtonType, | ||
radius: Double? = 20.0 | ||
) { | ||
super.init(frame: .zero) | ||
|
||
self.layer.cornerRadius = radius ?? 20.0 | ||
self.textLabel.text = type.message | ||
|
||
setupUI() | ||
} | ||
|
||
required public init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
private func setupUI() { | ||
self.addSubviews([textLabel]) | ||
|
||
snp.makeConstraints { | ||
$0.width.equalTo(83.0) | ||
$0.height.equalTo(40.0) | ||
} | ||
|
||
textLabel.snp.makeConstraints { | ||
$0.centerX.centerY.equalToSuperview() | ||
} | ||
} | ||
|
||
public func buttonYesChecked() { | ||
self.backgroundColor = DSKitAsset.Colors.gray50.color | ||
textLabel.textColor = DSKitAsset.Colors.blue500.color | ||
} | ||
|
||
public func buttonNoChecked() { | ||
self.backgroundColor = .clear | ||
textLabel.textColor = DSKitAsset.Colors.gray400.color | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
Projects/Modules/DSKit/Sources/Components/MaeumGaGymButton/Toggle/ToggleButtonType.swift
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,22 @@ | ||
import Foundation | ||
|
||
public enum ToggleButtonType { | ||
case image | ||
case album | ||
case timer | ||
case metronome | ||
|
||
var message: String { | ||
switch self { | ||
case .image: | ||
return "μ¬μ§" | ||
case .album: | ||
return "μ¨λ²" | ||
case .timer: | ||
return "νμ΄λ¨Έ" | ||
case .metronome: | ||
return "μ¨λ²" | ||
} | ||
} | ||
} | ||
|
119 changes: 119 additions & 0 deletions
119
Projects/Modules/DSKit/Sources/Components/MaeumGaGymVIew/MaeumGaGymToggleView.swift
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,119 @@ | ||
import UIKit | ||
import SnapKit | ||
import Then | ||
import RxSwift | ||
import RxCocoa | ||
|
||
open class MaeumGaGymToggleView: UIView { | ||
|
||
var toggle: Bool = true | ||
let disposeBag = DisposeBag() | ||
|
||
let view1 = UIView().then { | ||
$0.backgroundColor = .red | ||
} | ||
|
||
let view2 = UIView().then { | ||
$0.backgroundColor = .blue | ||
} | ||
|
||
private let imageToggleButton = MaeumGaGymToggleButton(type: .image) | ||
private let albumToggleButton = MaeumGaGymToggleButton(type: .album) | ||
|
||
public init( | ||
width: Double? = 430.0, | ||
height: Double? = 845.0 | ||
|
||
) { | ||
super.init(frame: .zero) | ||
|
||
setupUI(width: width ?? 430.0, height: height ?? 845.0) | ||
isToggleLR() | ||
buttonTap() | ||
} | ||
|
||
public required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
private func setupUI(width: Double, height: Double) { | ||
addSubviews([view2, view1, imageToggleButton, albumToggleButton]) | ||
|
||
view1.snp.makeConstraints { | ||
$0.width.equalTo(430.0) | ||
$0.height.equalTo(721.0) | ||
$0.centerX.equalToSuperview() | ||
$0.top.equalToSuperview().offset(0.0) | ||
} | ||
|
||
view2.snp.makeConstraints { | ||
$0.width.equalTo(430.0) | ||
$0.height.equalTo(721.0) | ||
$0.centerX.equalToSuperview() | ||
$0.top.equalToSuperview().offset(0.0) | ||
} | ||
|
||
snp.makeConstraints { | ||
$0.width.equalTo(width) | ||
$0.height.equalTo(height) | ||
} | ||
|
||
imageToggleButton.snp.makeConstraints { | ||
$0.leading.equalToSuperview().offset(124.0) | ||
$0.bottom.equalTo(self.safeAreaLayoutGuide).offset(-16.0) | ||
} | ||
|
||
albumToggleButton.snp.makeConstraints { | ||
$0.leading.equalTo(imageToggleButton.snp.trailing).offset(16.0) | ||
$0.bottom.equalTo(self.safeAreaLayoutGuide).offset(-16.0) | ||
} | ||
|
||
} | ||
|
||
private func isToggleLR() { | ||
if toggle == true { | ||
|
||
view2.removeFromSuperview() | ||
addSubviews([view1]) | ||
|
||
view1.snp.makeConstraints { | ||
$0.width.equalTo(430.0) | ||
$0.height.equalTo(721.0) | ||
$0.centerX.equalToSuperview() | ||
$0.top.equalToSuperview().offset(0.0) | ||
} | ||
|
||
imageToggleButton.buttonYesChecked() | ||
albumToggleButton.buttonNoChecked() | ||
} else { | ||
|
||
view1.removeFromSuperview() | ||
addSubviews([view2]) | ||
|
||
view2.snp.makeConstraints { | ||
$0.width.equalTo(430.0) | ||
$0.height.equalTo(721.0) | ||
$0.centerX.equalToSuperview() | ||
$0.top.equalToSuperview().offset(0.0) | ||
} | ||
|
||
albumToggleButton.buttonYesChecked() | ||
imageToggleButton.buttonNoChecked() | ||
} | ||
} | ||
|
||
private func buttonTap() { | ||
imageToggleButton.rx.tap | ||
.subscribe(onNext: { [weak self] in | ||
self?.toggle = true | ||
self?.isToggleLR() | ||
}).disposed(by: disposeBag) | ||
|
||
albumToggleButton.rx.tap | ||
.subscribe(onNext: { [weak self] in | ||
self?.toggle = false | ||
self?.isToggleLR() | ||
}).disposed(by: disposeBag) | ||
} | ||
|
||
} |