SwiftUI Previews Variants & States

SwiftUI Previews Variants & States

Preview multiple configurations by creating different states and variants in your preview provider.


Preview multiple variants side-by-side

Use a Group in your preview to render several configurations at once for quick comparison.

Example

Variants.swift

import SwiftUI

struct Badge: View { let color: Color; var body: some View { Circle().fill(color).frame(width: 40, height: 40) } }

struct Badge_Previews: PreviewProvider {
  static var previews: some View {
Group {
  Badge(color: .blue)
  Badge(color: .green)
}
} }

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *