The Power of UIAppearance - Styling iOS Apps

UIAppearance is an underappreciated gem in UIKit’s toolbox. It provides an elegant way to style UI elements globally across your app, thereby keeping your codebase DRY (Don’t Repeat Yourself) and maintainable. In this post, we’ll dive into UIAppearance and learn how to harness its power to style our iOS apps effectively. What is UIAppearance? UIAppearance is a protocol in UIKit that allows you to customize the appearance of all instances of a class....

May 28, 2023 · Mike Gopsill ·  UIKit

Programmatically Navigating a UIPageViewController using a UISegmentedControl

Let’s learn how to navigate a UIPageViewController using a UISegmentedControl in iOS. The UIPageViewController provides a way to display pages of content, where each page is managed by its own view controller. The UISegmentedControl displays segments and allows users to switch between them. We’ll begin by setting up the UISegmentedControl and UIPageViewController, then move on to connecting them by programmatically navigating the UIPageViewController based on the selection in the UISegmentedControl....

Creating a Text Publisher from UISearchBar in Combine

So you have a UISearchBar like the one shown below. A user typing into a search bar is an ideal input data stream for Combine. Ideally, we’d access a string publisher based on user input like so. let searchBar = UISearchBar() let searchText = searchBar.textPublisher Alas, it does not exist. I also tried performing Key-Value Observing with Combine on the searchBar or its text field. searchBar.publisher(for: \.text) searchBar.searchTextField.publisher(for: \.text) It compiles but emits no events....

Shake to Debug View Size

Ever wanted to quickly resize the simulator iOS screen so you can test how your view performs on smaller devices. Enter shake to debug. Shake is a good motion to use for presenting a debug menu because it’s easy to detect and can be done from anywhere. Whenever a user shakes their iPhone, the OS will call the motionEnded instance method of any UIResponder. As most UI elements inherit from UIResponder it’s easy to override motionEnded wherever we need, then display a debug menu when it happens....

January 5, 2023 · Mike Gopsill ·  UIKit

UIStackView

The UIStackView class aligns arrangedSubviews in a column or row. It reduces the amount of auto layout code required for grid-like layouts. It also handles constraints dynamically when you add, hide, insert and remove subviews. By default stack views arrange subviews horizontally in a row. This article will use horizontal stack views for this reason. The logic can easily be applied to vertical stack views by changing the axis property to ....

January 3, 2023 · Mike Gopsill ·  UIKit