Skip to content

Instantly share code, notes, and snippets.

@ivangodfather
Created March 18, 2020 17:59
Show Gist options
  • Select an option

  • Save ivangodfather/6b96bc3e0c6e57b98bf1d66a531ad946 to your computer and use it in GitHub Desktop.

Select an option

Save ivangodfather/6b96bc3e0c6e57b98bf1d66a531ad946 to your computer and use it in GitHub Desktop.
extension View {
func badge(num: Int) -> some View {
return self.overlay(
// ZStack(alignment: .topTrailing) {
Circle()
.fill(Color.red)
.frame(width: 24, height: 24)
.overlay(Text(num.description))
.transition(.scale)
.alignmentGuide(.trailing) { dim -> CGFloat in
return dim[HorizontalAlignment.center]
}
.alignmentGuide(.top) { dim -> CGFloat in
return dim[VerticalAlignment.center]
}
//}.background(Color.yellow)
, alignment: .topTrailing)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment