두 개의 Storyboard 생성합니다.
SceneDelegate.swift에서 코드 추가
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
var initialViewController = UIViewController()
var storyboard = UIStoryboard()
if UIDevice.current.userInterfaceIdiom == .pad{
storyboard = UIStoryboard(name: "iPad_Main", bundle: nil)
}
else{
storyboard = UIStoryboard(name: "Main", bundle: nil)
}
initialViewController = storyboard.instantiateInitialViewController()!
self.window = UIWindow(windowScene: windowScene)
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
}
결과
아이패드에서 가로모드로 따로 적용하기
기종 구분을 하는 UIDevice.current.userInterfaceIdiom을 viewDidLayoutSubviews()에 선언하여 구분
override func viewDidLayoutSubviews() {
if UIDevice.current.userInterfaceIdiom == .pad{
if UIScreen.main.bounds.size.width > UIScreen.main.bounds.size.height{
// 화면 크기 구하기
let screenSize = UIScreen.main.bounds.size
let componentsViewWidth = screenSize.width / 3
let imgBackgroundWidth = screenSize.width - componentsViewWidth
imgBackground.frame = CGRect(x: 0, y: 0, width: imgBackgroundWidth, height: screenSize.height)
componentsView.frame = CGRect(x: imgBackgroundWidth, y: 0, width: componentsViewWidth, height: screenSize.height)
componentsView.frame.size.width = componentsViewWidth
componentsView.frame.size.height = screenSize.height
componentsView.backgroundColor = .systemGray3
}
else{
componentsView.backgroundColor = .clear
}
}
}