-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#6] 영화,드라마 선택 화면 구현 #13
Changes from all commits
a0523c3
81af2e5
d5d6f81
d9f9872
8b29ab9
1cbf74f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,4 @@ SPEC CHECKSUMS: | |
|
||
PODFILE CHECKSUM: 5fd0e82f9fae1f129233777aee57aa7cc753fb9d | ||
|
||
COCOAPODS: 1.16.2 | ||
COCOAPODS: 1.12.1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "Vector.svg", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// FilterButton.swift | ||
// TodayVideo | ||
// | ||
// Created by iOS Dev on 1/16/25. | ||
// | ||
|
||
import UIKit | ||
|
||
final class FilterButton: UIButton { | ||
private let height: CGFloat = 50.0 | ||
private let leftRightMargin: CGFloat = 70.0 | ||
private var title = "" | ||
|
||
init(title: String) { | ||
super.init(frame: .zero) | ||
|
||
self.title = title | ||
self.setTitle(title, for: .normal) | ||
self.layer.cornerRadius = height / 2 | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
super.init(coder: coder) | ||
} | ||
|
||
func width() -> CGFloat { | ||
let titleWidth = title.width(size: 20) | ||
return titleWidth + leftRightMargin | ||
} | ||
|
||
func updateState() { | ||
if isSelected { | ||
changeColor(title: .buttonSelectedText, background: .buttonSelectedBackground) | ||
} else { | ||
changeColor(title: .buttonDefaultText, background: .buttonDefaultBackground) | ||
} | ||
} | ||
|
||
private func changeColor(title: UIColor, background: UIColor) { | ||
self.setTitleColor(title, for: .normal) | ||
self.backgroundColor = background | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// NextButton.swift | ||
// TodayVideo | ||
// | ||
// Created by iOS Dev on 1/16/25. | ||
// | ||
|
||
import UIKit | ||
import SnapKit | ||
|
||
final class NextButton: UIButton { | ||
private var currentView: UIViewController! | ||
|
||
init(location: UIViewController) { | ||
super.init(frame: .zero) | ||
|
||
self.currentView = location | ||
self.setImage(.nextButton, for: .normal) | ||
self.addTarget(self, action: #selector(pushToNextView), for: .touchUpInside) | ||
self.currentView.view.addSubview(self) | ||
self.layout(in: currentView.view) | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
func layout(in view: UIView) { | ||
self.snp.makeConstraints { make in | ||
make.width.equalTo(15.4) | ||
make.height.equalTo(23) | ||
make.trailing.equalTo(view.snp.trailing).offset(-41.6) | ||
make.bottom.equalTo(view.snp.bottom).offset(-78) | ||
} | ||
} | ||
|
||
@objc private func pushToNextView() { | ||
switch currentView { | ||
case is ContentView: | ||
guard let contentView = currentView as? ContentView else { return } | ||
contentView.presenter?.pushToGenreView() | ||
default: break | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// ContentPresenter.swift | ||
// TodayVideo | ||
// | ||
// Created by iOS Dev on 1/15/25. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol ContentPresenterProtocol { | ||
func pushToGenreView() | ||
} | ||
|
||
final class ContentPresenter: ContentPresenterProtocol { | ||
var router: ContentRouterProtocol? | ||
|
||
func pushToGenreView() { | ||
DispatchQueue.main.async { | ||
self.router?.pushToGenreView() | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// ContentRouter.swift | ||
// TodayVideo | ||
// | ||
// Created by iOS Dev on 1/15/25. | ||
// | ||
|
||
import UIKit | ||
|
||
protocol ContentRouterProtocol { | ||
func pushToGenreView() | ||
} | ||
|
||
final class ContentRouter: ContentRouterProtocol { | ||
weak var contentView: ContentView? | ||
|
||
static func createContentViewModule() -> ContentView { | ||
let view = ContentView() | ||
let presenter = ContentPresenter() | ||
let router = ContentRouter() | ||
|
||
view.presenter = presenter | ||
presenter.router = router | ||
router.contentView = view | ||
|
||
return view | ||
} | ||
|
||
// 장르 선택 화면으로 push | ||
func pushToGenreView() { | ||
// 다음 화면으로 이동을 위한 처리 코드 입니다. | ||
// let genreView = GenreRouter.createGenre | ||
// contentView?.navigationController?.pushViewController(genreView, animated: true) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// | ||
// ContentView.swift | ||
// TodayVideo | ||
// | ||
// Created by iOS Dev on 1/15/25. | ||
// | ||
|
||
import UIKit | ||
import SnapKit | ||
|
||
final class ContentView: UIViewController { | ||
var presenter: ContentPresenterProtocol? | ||
|
||
private var movieButton: FilterButton! | ||
private var tvButton: FilterButton! | ||
private let movie = "영화" | ||
private let tv = "TV" | ||
private lazy var selectedContent = movie | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
drawUI() | ||
buttonSelected(movieButton) | ||
} | ||
|
||
private func drawUI() { | ||
self.view.backgroundColor = .background | ||
|
||
// 영화, 드라마 버튼 | ||
/// 컨테이너 | ||
let height: CGFloat = 50.0 | ||
let containerView = UIView() | ||
let containerViewWidth: CGFloat = 300.0 | ||
|
||
self.view.addSubview(containerView) | ||
|
||
containerView.snp.makeConstraints { make in | ||
make.center.equalToSuperview() | ||
make.height.equalTo(height) | ||
make.width.equalTo(containerViewWidth) | ||
} | ||
|
||
/// 버튼 | ||
movieButton = FilterButton(title: movie) | ||
tvButton = FilterButton(title: tv) | ||
|
||
[movieButton, tvButton].forEach { button in | ||
button.addTarget(self, action: #selector(buttonSelected(_:)), for: .touchUpInside) | ||
containerView.addSubview(button) | ||
} | ||
|
||
let margin: CGFloat = 8.0 | ||
let buttonWidth = (containerViewWidth / 2) - margin | ||
|
||
movieButton.snp.makeConstraints { make in | ||
make.left.top.bottom.equalToSuperview() | ||
make.width.equalTo(buttonWidth) | ||
} | ||
|
||
tvButton.snp.makeConstraints { make in | ||
make.right.top.bottom.equalToSuperview() | ||
make.width.equalTo(buttonWidth) | ||
} | ||
|
||
// 다음 버튼 | ||
let _ = NextButton(location: self) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분이 잘 이해가지 않네요. 할당하지 않는데 왜 생성되었을까요? |
||
} | ||
|
||
@objc private func buttonSelected(_ sender: UIButton) { | ||
// 이미 선택되어 있는 버튼이면 return | ||
if sender.isSelected { | ||
return | ||
} | ||
|
||
sender.isSelected = !sender.isSelected | ||
|
||
DispatchQueue.main.async { | ||
if sender == self.movieButton { | ||
self.selectedContent = self.movie | ||
self.tvButton.isSelected = false | ||
self.tvButton.updateState() | ||
self.movieButton.updateState() | ||
} else { | ||
self.selectedContent = self.tv | ||
self.movieButton.isSelected = false | ||
self.movieButton.updateState() | ||
self.tvButton.updateState() | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// String+Extension.swift | ||
// TodayVideo | ||
// | ||
// Created by iOS Dev on 1/17/25. | ||
// | ||
|
||
import UIKit | ||
|
||
extension String { | ||
func width(size: CGFloat) -> CGFloat { | ||
let font = UIFont.systemFont(ofSize: size) | ||
let attributes: [NSAttributedString.Key: Any] = [.font: font] | ||
return self.size(withAttributes: attributes).width | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// UIImage+Extension.swift | ||
// TodayVideo | ||
// | ||
// Created by iOS Dev on 1/16/25. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UIImage { | ||
static let nextButton = UIImage(named: "next") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR 올리실 때에는 임의 주석 처리한 코드는 정리해주시는 것이 좋습니다.