7.10 · Initialisers, stack views, scroll views and modern buttons
Four everyday UIKit corners where the surprise is in the details: which initialiser runs, what a stack view really owns, how scrolling moves the coordinate system, and when a button configuration is applied.
Mental model. Most of these bugs come from a lifecycle you assumed: archives skip init(frame:), removeArrangedSubview keeps the view, scrolling edits bounds, and configuration handlers run at the next update pass.
Creating views
Initialiser paths and lazy view loading.
- Which initialisers run when a view or view controller is created in code, from a storyboard or from an archive, and when does the view of a controller get loaded?
A UIView has two designated initialisers: init(frame:) for code and init(coder:) for anything decoded (storyboards, nibs, archives). UIView() calls…
Containers and coordinates
Stack views, scroll views and converting points.
- What does a UIStackView own, and what is the difference between hiding, removing from arranged subviews and removing from the superview?
A stack view is a layout container that generates constraints for its arrangedSubviews; it does not draw anything itself. Arranged views are always also… - How does UIScrollView scroll, how do you convert points between views inside it, and does it clamp the content offset?
A scroll view does not move its subviews; it changes its own bounds.origin, and contentOffset is that origin. After setting the offset to 900 the check shows…
Modern controls
UIButton.Configuration and its update handler.
- What is UIButton.Configuration, and when does its configurationUpdateHandler run?
UIButton.Configuration (iOS 15) is a value type that describes a button's content and style: title, image, imagePlacement, imagePadding, contentInsets…
More in UIKit
- 7.1 · Hit testing, the responder chain and gesture recognisers
- 7.2 · UIView and CALayer, frame, bounds and center
- 7.3 · View controller lifecycle, containment, presentation and transitions
- 7.4 · Navigation, tab, split and page controllers
- 7.5 · Compositional layout, diffable data sources, cell reuse and prefetching
- 7.6 · UITableView, still asked and still everywhere
- 7.7 · Trait collections, size classes, safe area, keyboard and appearance
- 7.8 · Keyboard shortcuts, pointer, Apple Pencil and multitasking
- 7.9 · Hosting SwiftUI in UIKit and UIKit in SwiftUI
- 7.11 · Layout passes, retain cycles and menus
- 7.12 · Refreshing diffable cells, outlines and carousel layouts
- 7.13 · View-tree exercises and long navigation stacks