Post

Day 14 - TIL

코드베이스 UI설정

Day 14 - TIL

📘 Day 14 - Today I Learned

✅ 1. Main.storyboard 파일 삭제

  • Main.storyboard를 프로젝트에서 삭제 (Move to Trash)
  • Info.plist와 Build Settings에서의 참조도 함께 제거해야 함

✅ 2. Build Settings 확인

  • Project > Target > Build Settings 검색창에 storyboard 입력
  • UIKit Main Storyboard File Base Name 항목이 있다면 삭제

✅ 3. Info.plist 설정 수정

  • info.plist > Information Property List > Application Scene Maifest > Scene Configuration > Window Application Session Role > Item 0 > Storyboard NameDelete

✅ 4. SceneDelegate.swift 수정

1
2
3
4
5
6
7
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    guard let windowScene = (scene as? UIWindowScene) else { return }
    
    window = UIWindow(windowScene: windowScene)
    window?.rootViewController = ViewController() // 시작 뷰컨트롤러 지정
    window?.makeKeyAndVisible()
}

✅ 5. AppDelegate.swift 수정 (iOS 12 이하 대응 시)

1
2
3
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = ViewController() //시작뷰 컨트롤러 지정
window?.makeKeyAndVisible()

✅ 6. 앱 실행 테스트

  • ViewController.swfit 파일에가서 배경색 바꿔주기
1
2
3
4
5
override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        view.backgroundColor = .yellow // 배경색
}
  • 시뮬레이터에서 정상 실행되는지 확인

📌 정리

단계해야 할 작업설명
1️⃣Main.storyboard 삭제프로젝트 내 Main.storyboard 파일을 Move to Trash 처리
2️⃣Build Settings 정리Build Settings > UIKit Main Storyboard File Base Name 항목을 검색 후 삭제
3️⃣Info.plist 수정Storyboard Name 관련 키 삭제
Application Scene ManifestScene ConfigurationStoryboard Name 항목 삭제
4️⃣SceneDelegate.swift 설정scene(_:willConnectTo:) 내에 window 설정 후 rootViewController 지정
5️⃣AppDelegate.swift 설정 (iOS 12 이하)window 인스턴스 생성 후 rootViewController 지정 및 makeKeyAndVisible() 호출
6️⃣UI 정상 동작 테스트ViewController.swift에서 배경색 등 수정 후 시뮬레이터 실행 확인

📌 위 6단계를 마치면 스토리보드에 의존하지 않는 순수 코드 기반 iOS UI 프로젝트 환경이 완성! 💪

This post is licensed under CC BY 4.0 by the author.