[UIKit] InstagramClone: Get Started

Junyoung Park·2022년 11월 6일
0

UIKit

목록 보기
78/142
post-thumbnail
post-custom-banner

Build Instagram App: Part 1 (Swift 5) - 2022 - Xcode 11 - iOS Development

InstagramClone: Get Started

구현 목표

  • 인스타그램 클론 앱 구현

구현 태스크

  • 탭바 뷰 컨트롤러 연결

핵심 코드

private func setTabBar() {
        let vc1 = HomeViewController()
        let nav1 = UINavigationController(rootViewController: vc1)
        nav1.tabBarItem = UITabBarItem(title: nil, image: UIImage(systemName: "house")?.withTintColor(.black, renderingMode: .alwaysOriginal), selectedImage: UIImage(systemName: "house.fill")?.withTintColor(.black, renderingMode: .alwaysOriginal))
        
        let vc2 = ExploreViewController()
        let nav2 = UINavigationController(rootViewController: vc2)
        nav2.tabBarItem = UITabBarItem(title: nil, image: UIImage(systemName: "globe.desk")?.withTintColor(.black, renderingMode: .alwaysOriginal), selectedImage: UIImage(systemName: "globe.desk.fill")?.withTintColor(.black, renderingMode: .alwaysOriginal))

        let vc3 = CameraViewController()
        let nav3 = UINavigationController(rootViewController: vc3)
        nav3.tabBarItem = UITabBarItem(title: nil, image: UIImage(systemName: "plus.circle")?.withTintColor(.black, renderingMode: .alwaysOriginal), selectedImage: UIImage(systemName: "plus.circle.fill")?.withTintColor(.black, renderingMode: .alwaysOriginal))

        let vc4 = NotificationViewController()
        let nav4 = UINavigationController(rootViewController: vc4)
        nav4.tabBarItem = UITabBarItem(title: nil, image: UIImage(systemName: "bell")?.withTintColor(.black, renderingMode: .alwaysOriginal), selectedImage: UIImage(systemName: "bell.fill")?.withTintColor(.black, renderingMode: .alwaysOriginal))

        let vc5 = ProfileViewController()
        let nav5 = UINavigationController(rootViewController: vc5)
        nav5.tabBarItem = UITabBarItem(title: nil, image: UIImage(systemName: "person")?.withTintColor(.black, renderingMode: .alwaysOriginal), selectedImage: UIImage(systemName: "person.fill")?.withTintColor(.black, renderingMode: .alwaysOriginal))
        tabBar.backgroundColor = .white
        setViewControllers([nav1, nav2, nav3, nav4, nav5], animated: true)
    }
  • 탭 뷰 컨트롤러 내 네비게이션으로 감싼 각 뷰 컨트롤러를 탭 아이템으로 추가
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let scene = (scene as? UIWindowScene) else { return }
        let window = UIWindow(windowScene: scene)
        window.makeKeyAndVisible()
        window.rootViewController = TabBarViewController()
        self.window = window
    }
  • 스토리보드 제거 및 탭바 뷰 컨트롤러를 루트 뷰 컨트롤러로 조정

구현 화면

강의에서 사용되는 기존의 컴플리션 핸들러 스타일이 아니라 MVVM 양식에 맞춰 컴바인을 사용해보자. 별도로 컬렉션 뷰 또는 테이블 뷰를 사용한다면 이전에 공부한 Diffable Data Source를 사용해보자.

profile
JUST DO IT
post-custom-banner

0개의 댓글