Hello guys, I want to show a badge on an object in SwiftUI (I want the rectangle to show the badge on it every time I press it). I did some tests, but it isn't working. Can someone help me to build this?
Thanks a lot.
Add badge to an object
Show your code, so people can comment on your work so far.
Here's my code:
I want to show the badge on the badge on the rectangle each time I press on it. But currently it isn't working what I did wrong?
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
var body: some View {
Button(action: {
badge(9)
}, label: {
Rectangle()
.frame(width: 180, height: 200)
.foregroundColor(.blue)
})
}
}
PlaygroundPage.current.setLiveView(ContentView())