Get ready for your next interview with our comprehensive question library
UIView is the fundamental building block for all visual elements in iOS. It represents a rectangular area on the screen and handles drawing and user interaction within that area. Views can contain other views (subviews) and form a view hierarchy.
UIViewController manages a collection of views and coordinates the logic between the model and view layers. It handles view lifecycle events, user interactions, and navigation between different screens.
// UIView - represents visual element
let myView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
myView.backgroundColor = .blue
// UIViewController - manages views and logic
class MyViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(myView)
}
}
The view hierarchy is a tree-like structure where views contain other views as subviews. Each view has a superview (parent) and can have multiple subviews (children). The root view is typically managed by a view controller.
Key characteristics:
let parentView = UIView()
let childView1 = UIView()
let childView2 = UIView()
parentView.addSubview(childView1)
parentView.addSubview(childView2)
// childView2 will be drawn on top of childView1
Key UIView properties include:
Auto Layout is a constraint-based layout system that automatically calculates the size and position of views based on rules (constraints) you define. It's important because:
Auto Layout uses mathematical relationships between views instead of fixed frames, making UIs flexible and maintainable.
UITableView displays data in a single column of rows. It's optimized for vertical scrolling and is ideal for lists, settings screens, and hierarchical data.
UICollectionView displays data in a customizable grid layout. It supports multiple columns, horizontal scrolling, and complex layouts like grids, carousels, or custom arrangements.
Key differences:
Upgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumAccess all premium content - interview questions, and other learning resources
We regularly update our features and content, to ensure you get the most relevant and updated premium content.
1000 monthly credits
Cancel anytime