Project/NETFLIX
NETFLIX CLONE 1편 (메인 스토리 보드 삭제, 탭바 컨트롤러 구성)
밤새는탐험가
2024. 5. 3. 13:28
✅ 메인 스토리 보드 삭제
✅ 탭바 컨트롤러 삽입
✅ 메인 스토리 보드 삭제
- 메인 스토리 파일 삭제
- info → 메인 스토리 보드 삭제
- Build Settings → 메인 스토리 보드 삭제
- SceneDelegate 파일 내에 아래 코드 삽입
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(frame: windowScene.coordinateSpace.bounds)
window?.windowScene = windowScene
window?.rootViewController = ViewController()
window?.makeKeyAndVisible()
}
✅ 탭바 컨트롤러 삽입
- 기존의 ViewController.swift 파일을 MainTabBarViewController 명으로 변경
- UIViewController → UITabBarController 를 준수한다고 할 것
- SceneDelegate 파일 내에서 ViewController → MainTabBarController로 따르게 할 것
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(frame: windowScene.coordinateSpace.bounds)
window?.windowScene = windowScene
window?.rootViewController = MainTabBarViewController()
window?.makeKeyAndVisible()
}
✅ 메인 탭바 컨트롤러 코드 작성
- 탭바에 들어갈 컨트롤러 생성
- 각 건트롤러 탭바에 적용
import UIKit
class MainTabBarViewController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .systemYellow
let vc1 = UINavigationController(rootViewController: HomeViewController())
let vc2 = UINavigationController(rootViewController: UpcomingViewController())
let vc3 = UINavigationController(rootViewController: SearchViewController())
let vc4 = UINavigationController(rootViewController: DownloadsViewController())
vc1.tabBarItem.image = UIImage(systemName: "house")
vc2.tabBarItem.image = UIImage(systemName: "play.circle")
vc3.tabBarItem.image = UIImage(systemName: "magnifyingglass")
vc4.tabBarItem.image = UIImage(systemName: "arrow.down.to.line")
vc1.title = "Home"
vc2.title = "Coming Soon"
vc3.title = "Top Search"
vc4.title = "Downloads"
tabBar.tintColor = .label
setViewControllers([vc1,vc2,vc3,vc4], animated: true)
}
}
https://youtu.be/LWGr9fQR498?si=t3iDCLqpwGxNTXeD