在iOS 15 新增了badge() modifier

1.给tab view items 添加数字

struct ContentView: View {
    var body: some View {
        VStack {
            TabView {
                Text("Your home screen here")
                    .tabItem {
                        Label("Home", systemImage: "house")
                    }
                    .badge(5)

                Text("Your Me screen here")
                    .tabItem {
                        Label("Me", systemImage: "house")
                    }
                    .badge(1)
            }  
        }
    }
}

demo

2.在List rows里面,在右侧显示字符串,并且默认secondary color

struct ContentView: View {
    var body: some View {
        VStack {
            List {
                Text("Wi-Fi")
                    .badge("LAN Solo")

                Text("Bluetooth")
                    .badge("On")
            }
            
        }
    }
}

demo 参考