BadgeSymbol.swift 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. See LICENSE folder for this sample’s licensing information.
  3. Abstract:
  4. A view that display a symbol in a badge.
  5. */
  6. import SwiftUI
  7. struct BadgeSymbol: View {
  8. static let symbolColor = Color(red: 79.0 / 255, green: 79.0 / 255, blue: 191.0 / 255)
  9. var body: some View {
  10. GeometryReader { geometry in
  11. Path { path in
  12. let width = min(geometry.size.width, geometry.size.height)
  13. let height = width * 0.75
  14. let spacing = width * 0.030
  15. let middle = width / 2
  16. let topWidth = 0.226 * width
  17. let topHeight = 0.488 * height
  18. path.addLines([
  19. CGPoint(x: middle, y: spacing),
  20. CGPoint(x: middle - topWidth, y: topHeight - spacing),
  21. CGPoint(x: middle, y: topHeight / 2 + spacing),
  22. CGPoint(x: middle + topWidth, y: topHeight - spacing),
  23. CGPoint(x: middle, y: spacing)
  24. ])
  25. path.move(to: CGPoint(x: middle, y: topHeight / 2 + spacing * 3))
  26. path.addLines([
  27. CGPoint(x: middle - topWidth, y: topHeight + spacing),
  28. CGPoint(x: spacing, y: height - spacing),
  29. CGPoint(x: width - spacing, y: height - spacing),
  30. CGPoint(x: middle + topWidth, y: topHeight + spacing),
  31. CGPoint(x: middle, y: topHeight / 2 + spacing * 3)
  32. ])
  33. }
  34. .fill(Self.symbolColor)
  35. }
  36. }
  37. }
  38. struct BadgeSymbol_Previews: PreviewProvider {
  39. static var previews: some View {
  40. BadgeSymbol()
  41. }
  42. }