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.

  1. 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? 7.10.1 · L2
    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.

  1. What does a UIStackView own, and what is the difference between hiding, removing from arranged subviews and removing from the superview? 7.10.2 · L2
    A stack view is a layout container that generates constraints for its arrangedSubviews; it does not draw anything itself. Arranged views are always also…
  2. How does UIScrollView scroll, how do you convert points between views inside it, and does it clamp the content offset? 7.10.3 · L3
    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.

  1. What is UIButton.Configuration, and when does its configurationUpdateHandler run? 7.10.4 · L3
    UIButton.Configuration (iOS 15) is a value type that describes a button's content and style: title, image, imagePlacement, imagePadding, contentInsets…

More in UIKit