Created
March 23, 2020 11:39
-
-
Save ivangodfather/482a316d9c9d8c94198ca6a3a8de934d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: 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