Updated for Xcode 12.0
New in iOS 14
SwiftUI has a dedicated view type for showing text and icons side by side, which will be particularly helpful for menus, lists, and more.
To use labels, you can either use SF Symbols like this:
Label("Your account", systemImage: "person.crop.circle")
Or use your own images, like this:
Label("Welcome to the app", image: "logo")
You can scale the text and icon in parallel using the font()
modifier, like this:
Label("Your account", systemImage: "person.crop.circle")
.font(.title)
Note: In the current beta the alignment between icon and text seems easy to get wrong – hopefully this will improve!
If you want, you can provide entirely custom views for the text and image, like this:
Label {
Text("Paul Hudson")
.foregroundColor(.primary)
.font(.largeTitle)
.padding()
.background(Color.gray.opacity(0.2))
.clipShape(Capsule())
} icon: {
RoundedRectangle(cornerRadius: 10)
.fill(Color.blue)
.frame(width: 64, height: 64)
}
SPONSORED Building in-app subscriptions are hard. RevenueCat makes it simple. With their open source SDKs, you can painlessly implement subscriptions for your app in hours, not months.
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.