Instantly share code, notes, and snippets.
Last active
October 17, 2023 14:55
-
Star
(1)
1
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save devs-rootstrap/0c452efdd1b798392071f588f0a71edb to your computer and use it in GitHub Desktop.
SwiftUI Button Example
This file contains 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
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
VStack(spacing: 20) { | |
Text("SwiftUI Button") | |
.font(.largeTitle) | |
Text("With Backgroud") | |
.font(.title) | |
.foregroundColor(.gray) | |
/* Solid Button */ | |
Button(action: {}) { | |
Text("Solid Button") | |
.padding() | |
.foregroundColor(.white) | |
.background(.orange) | |
.cornerRadius(10) | |
} | |
/* Button with Shadow */ | |
Button(action: {}) { | |
Text("Button with Shadow") | |
.padding() | |
.foregroundColor(.white) | |
.background(.orange) | |
.cornerRadius(10) | |
} | |
.shadow(color: .red, radius: 15, y: 5) | |
/* Rounded Button */ | |
Button(action: {}) { | |
Text("Rounded Button") | |
.padding() | |
.foregroundColor(.white) | |
.background(.orange) | |
.cornerRadius(100) | |
} | |
} | |
} | |
} |
This file contains 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
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
VStack(spacing: 20) { | |
Text("SwiftUI Button") | |
.font(.largeTitle) | |
Text("Border Shape") | |
.font(.title) | |
.foregroundColor(.gray) | |
/* Border Shape */ | |
Button("Automatic") {} | |
.buttonStyle(.bordered) | |
.controlSize(.large) | |
.buttonBorderShape(.automatic) | |
Button("Capsule") {} | |
.buttonStyle(.bordered) | |
.controlSize(.large) | |
.buttonBorderShape(.capsule) | |
Button("Rounded") {} | |
.buttonStyle(.bordered) | |
.controlSize(.large) | |
.buttonBorderShape(.roundedRectangle) | |
} | |
} | |
} |
This file contains 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
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
VStack(spacing: 20) { | |
Text("SwiftUI Button") | |
.font(.largeTitle) | |
Text("With Borders") | |
.font(.title) | |
.foregroundColor(.gray) | |
/* Square Border Button */ | |
Button(action: {}) { | |
Text("Border Button") | |
.padding() | |
.border(.blue) | |
} | |
/* Square Border Button */ | |
Button(action: {}) { | |
Text("Border Button") | |
.padding() | |
.background( | |
RoundedRectangle(cornerRadius: 10) | |
.stroke(.blue, lineWidth: 1) | |
) | |
} | |
} | |
} | |
} |
This file contains 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
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
VStack(spacing: 20) { | |
Text("SwiftUI Button") | |
.font(.largeTitle) | |
Text("Control Size") | |
.font(.title) | |
.foregroundColor(.gray) | |
/* Control Size */ | |
Button("Mini") {} | |
.buttonStyle(.bordered) | |
.controlSize(.mini) | |
Button("Small") {} | |
.buttonStyle(.bordered) | |
.controlSize(.small) | |
Button("Regular") {} | |
.buttonStyle(.bordered) | |
.controlSize(.regular) | |
Button("Large") {} | |
.buttonStyle(.bordered) | |
.controlSize(.large) | |
} | |
} | |
} |
This file contains 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
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
VStack(spacing: 20) { | |
Text("SwiftUI Button") | |
.font(.largeTitle) | |
Text("Enabled & Disabled") | |
.font(.title) | |
.foregroundColor(.gray) | |
/* Disabled */ | |
Button("Enabled") {} | |
.buttonStyle(.borderedProminent) | |
.tint(.blue) | |
.controlSize(.large) | |
Button("Disabled") {} | |
.buttonStyle(.borderedProminent) | |
.tint(.blue) | |
.controlSize(.large) | |
.disabled(true) | |
} | |
} | |
} |
This file contains 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
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
VStack(spacing: 20) { | |
Text("SwiftUI Button") | |
.font(.largeTitle) | |
Text("Examples") | |
.font(.title2) | |
.foregroundColor(.gray) | |
/* Default Button */ | |
Button("I'm a Default Button") { | |
// Your code here | |
} | |
/* Customizing the Text */ | |
Button(action: { | |
// Your code here | |
}) { | |
Text("Custom text style") | |
.font(.title) | |
} | |
Button(action: { | |
// Your code here | |
}) { | |
Text("Red thin text") | |
.font(.title) | |
.fontWeight(.thin) | |
.foregroundColor(.red) | |
} | |
} | |
} | |
} |
This file contains 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
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
VStack(spacing: 20) { | |
Text("SwiftUI Button") | |
.font(.largeTitle) | |
Text("Style") | |
.font(.title) | |
.foregroundColor(.gray) | |
/* Button Styles */ | |
Button("Plain") {} | |
.buttonStyle(.plain) | |
Button("Automatic") {} | |
.buttonStyle(.automatic) | |
Button("Bordered") {} | |
.buttonStyle(.bordered) | |
Button("Bordered Prominent") {} | |
.buttonStyle(.borderedProminent) | |
Button("Borderless") {} | |
.buttonStyle(.borderless) | |
} | |
} | |
} |
This file contains 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
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
VStack(spacing: 20) { | |
Text("SwiftUI Button") | |
.font(.largeTitle) | |
Text("Symbols") | |
.font(.title) | |
.foregroundColor(.gray) | |
/* Button with Symbols */ | |
Button(action: {}) { | |
Image(systemName: "magnifyingglass") | |
Text("Search") | |
.padding(.horizontal) | |
} | |
.padding() | |
.background(.blue) | |
.foregroundColor(.white) | |
.cornerRadius(10) | |
Button(action: {}) { | |
VStack { | |
Image(systemName: "message.fill") | |
Text("Message") | |
.padding(.horizontal) | |
} | |
} | |
.padding() | |
.background(.blue) | |
.foregroundColor(.white) | |
.cornerRadius(.infinity) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment