Center the time in apps on Apple Watch app

Hi, I'll start by saying that I'm a new developer for apps for Apple devices, especially for Apple Watch, so please have mercy I'm trying to create an app for Apple Watch (WatchOs 10+) and I have a problem, my interface is made up of 3 buttons, one at the bottom of the screen and two smaller ones positioned on the top of the screen, each in their respective corners (one at the top right and the other at the top left). By positioning these buttons on the top of the screen, the top right button is covered by the default Apple time, and I would like to move it to the center, thus creating two side buttons and the time in the center. I'm also asking if there's a way to remove it since it's not useful to me, but reading some forums it seems that without it I don't pass the app verification, so I'm waiting for your advice. The only app I've seen in circulation on the app store that has the centered clock is petey.

Answered by Frameworks Engineer in 827903022

Hi Andrei,

We love to see new developers building apps for watchOS! In terms of your time placement issue, it sounds like you might not be using the Toolbar APIs. You can set up a toolbar to have leading/trailing items in the top bar (along with a bottom item) with the following code:

SomeView()
    .toolbar {
        ToolbarItem(placement: .topBarLeading) {
            Button("Top Leading Button!", systemImage: "star") {
                // do things here
            }
        }
        ToolbarItem(placement: .topBarTrailing) {
            Button("Top Trailing Button!", systemImage: "square") {
                // do things here
            }
        }
        ToolbarItem(placement: .bottomBar) {
            Button("Bottom Button!", systemImage: "triangle") {
                // do things here
            }
        }

If you use these APIs, the system will automatically place the time in the center when you provide a top bar trailing item.

If you're still having trouble getting the time where you'd like it after adopting the Toolbar APIs, please post the code for your view here.

Accepted Answer

Hi Andrei,

We love to see new developers building apps for watchOS! In terms of your time placement issue, it sounds like you might not be using the Toolbar APIs. You can set up a toolbar to have leading/trailing items in the top bar (along with a bottom item) with the following code:

SomeView()
    .toolbar {
        ToolbarItem(placement: .topBarLeading) {
            Button("Top Leading Button!", systemImage: "star") {
                // do things here
            }
        }
        ToolbarItem(placement: .topBarTrailing) {
            Button("Top Trailing Button!", systemImage: "square") {
                // do things here
            }
        }
        ToolbarItem(placement: .bottomBar) {
            Button("Bottom Button!", systemImage: "triangle") {
                // do things here
            }
        }

If you use these APIs, the system will automatically place the time in the center when you provide a top bar trailing item.

If you're still having trouble getting the time where you'd like it after adopting the Toolbar APIs, please post the code for your view here.

Hi, Thank you so much you saved my life, but a much more general question, where can I find this information? I searched everywhere but I didn't find anything, if you have books, documentation, links, videos to recommend it would be perfect. Thank you so much again

A set of great resources to get started with SwiftUI are the SwiftUI Tutorials — specifically in Chapter 4, there's a section on bringing an app to watchOS, but many of the concepts that are demonstrated on other platforms apply on Apple Watch. Additionally, a great talk on modern watchOS app design is Design and Build Apps for watchOS 10 from WWDC23, and an excellent article that goes over modern watchOS UI concepts is Creating an intuitive and effective UI in watchOS 10.

Center the time in apps on Apple Watch app
 
 
Q