What I am working on
As I continued working on MakeItSo this week, I realised that the app’s navigation bar title looks slightly different than Apple’s Reminder app. Turns out they started using round versions of the San Francisco font a while back.
I don’t know about you, but I’ve got the impression that SwiftUI seems to follow Alan Kay’s adage “Simple things should be simple, complex things should be possible” (source) - specifying which font to use is a prime example of this principle!
SwiftUI defines a number of defaults for font styles most apps will be using over and over again, and these are defined as constants on
caption, and others are text styles you will find in almost any app.
In addition, you can easily string together your own font to meet your app’s needs. For example, here is how you can create a rounded variant of the system font for any text labels that are of the style body:
.font(.system(.body, design: .rounded))
By assigning this to the root view of your application, this font style will now be used in every view of your app’s view hierarchy. Unfortunately, this doesn’t apply to the text labels in the navigation bar. To achieve this, we have to use fall back to UIKit and use the UIAppearance API:
let navGarAppearance = UINavigationBarAppearance) navBarAppearance. largeTitleTextAttributes[.font] = UIFont.roundedLargeTitle() navBarAppearance.largeTitleTextAttributes[.foregroundColor] = UIColor(Color.accentcolor) navBarAppearance.titleTextAttributes[.font] = UIFont.roundedHeadline() // I purposefully don't set the foreground color for normal text nav bar - // in Reminders. app, this isn't tinted as well! // navBarAppearance. titleTextAttributes[.foregroundColor] = foregroundColor UINavigationBar .appearance(). standardAppearance = navBarAppearance
Now, while this certainly is one of those cases where we can implement a UI feature that is not (yet) supported by SwiftUI, it certainly feels like an easy-enough addition to the existing APIs that Apple should try and ship in the next point release of SwiftUI. Judging by the number of articles out there explaining how to implement this and the number of questions on StackOverflow, this is an issue many developers are running into. Maybe a good project for one of the interns that the SwiftUI team will be hosting?
Call it perception bias, but it seems to me this week was full of Combine content. First, Antoine took us on a deep dive about when to use use RunLoop.main vs. DispatchQueue.main (definitely worth reading if you care about smooth scrolling). Next, Natascha explained what back-pressure means in Combine and showed us some real-world examples. And finally, Rony gave a useful extension for Publisher that allows us to sink events without creating retain cycles.