Skip to content

Instantly share code, notes, and snippets.

@l4u
Last active January 24, 2023 04:24
Show Gist options
  • Save l4u/9440f62bb3ed0bb880a6 to your computer and use it in GitHub Desktop.
Save l4u/9440f62bb3ed0bb880a6 to your computer and use it in GitHub Desktop.
Create a UIWindow programmatically without using storyboards in swift
window = UIWindow(frame: UIScreen.mainScreen().bounds)
if let window = window {
window.backgroundColor = UIColor.whiteColor()
window.rootViewController = UIViewController()
window.makeKeyAndVisible()
}
@SraavanChevireddy
Copy link

Here

mainScreen bounds works and window adjusts according to size when switched landscape or portrait automatically. This is perfect.
Question: But, why doesn't it adpat automatically with in a UIViewController for its sub components ?

@l4u
Copy link
Author

l4u commented Jan 24, 2023

@SraavanChevireddy you will need to learn about auto layout / constraints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment