SwiftUI Custom Styling

In this article, we are going to discuss a simple but useful SwiftUI feature. You probably already experimented with it, and think it is just a trivial exercise… but don’t fly away so soon. I’ll present the basic setup of a button and a toggle style, but then, we’ll see some aspects that are usually … Read more

Frame Behaviors with SwiftUI

SwiftUI Frame Tricks

In this post, I am going to talk about .frame(). Seriously. I know it may seem like a boring and simple topic. If you follow my blog, you’ve probably noticed that I try to post only advanced SwiftUI techniques. You may be surprised, but .frame() is far from basic. It has some interesting behaviors and … Read more

Advanced SwiftUI Transitions

Transitions Banner

In this article, we are going to explore the different options for using transitions. We’ll discuss several aspects of them. From the basic to the most advanced. How to configure, combine and trigger them. We’ll study what are the pre-existing transitions, but more importantly, how we can create our own. When doing so, the information … Read more

Alignment Guides in SwiftUI

Alignment guides are a powerful, but usually underused layout tool. In many cases, they help us avoid more complex options, such as anchor preferences. As you can see in this example, changes to the alignment can be automatically (and easily) animated too. Code: alignment-guides-animation.swift If you ever tried using alignment guides though, chances are, you … Read more

Dismiss Gesture for SwiftUI Modals

iPad Gesture

I’ll say it loud and clear. What you are about to read, is a hack. As such, it comes with no warranty. Apple may change the way modals are presented in SwiftUI, which may in turn render this article completely useless. But this blog is all about experimenting and learning… so the content of this … Read more

Advanced SwiftUI Animations – Part 3: AnimatableModifier

Film Strip

We have seen how the Animatable protocol has helped us in animating paths and transform matrices. In this last part of the series, we will take it even further. The AnimatableModifier is the most powerful of all three. With it, we have no limits on what we can accomplish. The name says it all: AnimatableModifier. … Read more

Trigonometric Recipes for SwiftUI

Pi

I love trigonometry. Probably because my father taught me so well. He made me see all the wonderful real-life applications it has. Everywhere you look, there’s a problem you can solve with those simple functions. From high tech problems like GPS positioning, to simple questions, such as what is the height of a building. So … Read more

Advanced SwiftUI Animations – Part 2: GeometryEffect

Film Strip

In the first part of this series, I introduced the Animatable protocol, and how we can use it to animate Paths. Next we are going to use the same protocol to animate transform matrices, using a new tool: GeometryEffect. If you haven’t read part 1, and don’t know what the Animatable protocol is, you should … Read more

Advanced SwiftUI Animations – Part 1: Paths

Film Strip

In this article we are going to dive into some advanced techniques to create SwiftUI animations. I will talk extensively about the Animatable protocol, its trusty companion animatableData, the powerful and often ignored GeometryEffect and the completely overlooked but almighty AnimatableModifier protocol. These are all topics that have been totally ignored by the official documentation, … Read more

ScrollView – Pull to Refresh

Pull To Refresh

At the time of writing, ScrollView in SwiftUI is not very customizable. A feature many may be missing, is the ability to refresh its contents when the view is pulled. Fortunately, using view preferences, we can manage to add such behaviour. Once we finished coding our new view, using refreshable ScrollViews will be very easy, … Read more

View Extensions for Better Code Readability

When we are writing our view code, we want to make it look as clean as possible. Good indentation, avoiding long lines, clear and meaningful names, etc. It all contributes to code readability. Nevertheless, sometimes it gets out of control and our views become hard to read and ugly to look at. You probably already … Read more

Inspecting the View Tree – Part 3: Nested Views

Inspecting the View Tree

Dealing with Preferences for Nested Views In the previous part of this series, we introduced SwiftUI anchor preferences. Now we are finally coming out of the forest. In this last part, we will put everything together. We will also learn how SwiftUI handles preferences of nested views, plus some other uses of Anchor<T>. As usual, … Read more

Inspecting the View Tree – Part 2: AnchorPreferences

Inspecting the View Tree

In the first part of this article, we introduced the use of preferences. These are very useful to communicate information upwards (from children to ancestors). By defining the associated type of our PreferenceKey, we now know that we can put anything we want in there. In this second part, the moment for Anchor Preferences to … Read more

Inspecting the View Tree – Part 1: PreferenceKey

Inspecting the View Tree

With SwiftUI, we normally don’t need to worry about what happens internally on our child views. Each happily does its own thing. However, life is not always normal. When we face these circumstances, SwiftUI provides us with some great tools. Unfortunately, its documentation is brief at best. This three part article tries to put a … Read more

GeometryReader to the Rescue

GeometryReader

Most of the time, SwiftUI will do its Layout Magic and life will be wonderful. However, there are times (many times), when we require more control over the layout of our custom views. For these moments, we have several tools. The first one we are going to explore is GeometryReader. What the Parent Wants When … Read more

SwiftUI’s Layout Magic

SwiftUI Layout Magic

A New Way of Thinking As Apple put it during their 2019 WWDC, the new SwiftUI declarative views may be considered recipes. Each containing instructions on how to build themselves. Following on this food analogy, imagine you have the main recipe, which in turn is made of other preparations. A sauce, grilled fish, garnish, etc. … Read more

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close