Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ivangodfather/482a316d9c9d8c94198ca6a3a8de934d to your computer and use it in GitHub Desktop.
Save ivangodfather/482a316d9c9d8c94198ca6a3a8de934d to your computer and use it in GitHub Desktop.
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
import SwiftUI
import Combine
import SwiftUI
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) { $0[HorizontalAlignment.center] }
.alignmentGuide(.top) { $0[VerticalAlignment.center] }
}
, alignment: .topTrailing)
}
}
struct ContentView : View {
@State var badgeCount = 0
var body: some View {
VStack {
Rectangle()
.fill(Color.blue)
.frame(width: 100, height: 100)
.badge(num: badgeCount)
.border(Color.green)
Stepper("Update", value: $badgeCount.animation())
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
PlaygroundPage.current.liveView = UIHostingController(
rootView: ContentView()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment