-
Notifications
You must be signed in to change notification settings - Fork 0
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
[#6] 영화,드라마 선택 화면 구현
- Loading branch information
Showing
16 changed files
with
353 additions
and
35 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 |
---|---|---|
|
@@ -13,4 +13,4 @@ SPEC CHECKSUMS: | |
|
||
PODFILE CHECKSUM: 5fd0e82f9fae1f129233777aee57aa7cc753fb9d | ||
|
||
COCOAPODS: 1.16.2 | ||
COCOAPODS: 1.12.1 |
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
12 changes: 12 additions & 0 deletions
12
TodayVideo/TodayVideo/Assets.xcassets/next.imageset/Contents.json
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,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "Vector.svg", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
TodayVideo/TodayVideo/Assets.xcassets/next.imageset/Vector.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,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 | ||
} | ||
} |
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,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 | ||
} | ||
} | ||
} |
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 @@ | ||
// | ||
// 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() | ||
} | ||
} | ||
} |
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,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) | ||
} | ||
} |
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,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 | ||
|
||
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) | ||
} | ||
|
||
@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() | ||
} | ||
} | ||
} | ||
} |
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,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 | ||
} | ||
} |
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
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,12 @@ | ||
// | ||
// UIImage+Extension.swift | ||
// TodayVideo | ||
// | ||
// Created by iOS Dev on 1/16/25. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UIImage { | ||
static let nextButton = UIImage(named: "next") | ||
} |
Oops, something went wrong.