Skip to content

Instantly share code, notes, and snippets.

@anupamchugh
Created July 8, 2020 18:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anupamchugh/e4df9b9734634a5cf59b51f784e08610 to your computer and use it in GitHub Desktop.
Save anupamchugh/e4df9b9734634a5cf59b51f784e08610 to your computer and use it in GitHub Desktop.
struct ContentView: View {
var body: some View {
VStack{
Label("Hello Label", systemImage: "sun.min")
.font(.system(.title, design: .rounded))
Label("Title only label", systemImage: "sun.min")
.font(.system(.title, design: .rounded))
.labelStyle(TitleOnlyLabelStyle())
Label("Icon only label", systemImage: "sun.min")
.font(.system(.title, design: .rounded))
.labelStyle(IconOnlyLabelStyle())
.foregroundColor(.red)
Label(title: {Text("Another label")}, icon: {Image(systemName: "sun.min")})
Label("Context Menu Label", systemImage: "sun.min")
.foregroundColor(.blue)
.labelStyle(VLabelStyle())
.font(.system(.title, design: .rounded))
.contextMenu
{
Button(action: {
print("action 1")
}) {
Label("Option 1", systemImage: "sun.min")
}
Button(action: {
print("action 2")
}) {
Label("Option 2", systemImage: "trash.fill")
}
}
}
}
struct VLabelStyle: LabelStyle {
func makeBody(configuration: Configuration) -> some View {
VStack {
configuration.icon
configuration.title
}
}
}
}
struct DateView: View {
var body: some View {
VStack{
Text(Date(),style: .date)
.padding()
Text(Date().addingTimeInterval(3600),style: .time)
.padding()
Text(Date().addingTimeInterval(60),style: .offset)
.padding()
Text(Date().addingTimeInterval(60), style: .relative)
.padding()
Text("Timer: \(Text(Date().addingTimeInterval(60), style: .timer))")
.padding()
}
}
}
struct FancyTexts: View {
var body: some View {
VStack{
Text("Images in Text \(Image(systemName: "heart.fill"))\n")
.font(.title2)
.foregroundColor(.red)
+
Text(Image(systemName: "sun.min"))
.foregroundColor(.yellow)
.font(.system(size: 60, weight: .bold, design: .rounded))
.foregroundColor(.blue)
+
Text(Image(systemName: "gamecontroller")).foregroundColor(.green)
.font(.system(size: 60, weight: .bold, design: .rounded))
+
Text(Image(systemName: "moon.zzz"))
.foregroundColor(.blue)
.font(.system(size: 60, weight: .heavy, design: .monospaced))
.foregroundColor(.blue)
}.multilineTextAlignment(.center)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment