Skip to content

Instantly share code, notes, and snippets.

@devs-rootstrap
Last active October 17, 2023 14:55
Show Gist options
  • Save devs-rootstrap/0c452efdd1b798392071f588f0a71edb to your computer and use it in GitHub Desktop.
Save devs-rootstrap/0c452efdd1b798392071f588f0a71edb to your computer and use it in GitHub Desktop.
SwiftUI Button Example
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)
}
}
}
}
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)
}
}
}
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)
)
}
}
}
}
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)
}
}
}
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)
}
}
}
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)
}
}
}
}
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)
}
}
}
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