SwiftUI Button & TextField Info
First off, an excellent resource is
Mastering Buttons in SwiftUI
TextField in SwiftUI
Don't forget to use the Environment Object if possible!
import UIKit
import SwiftUI
import PlaygroundSupport
var str = "Hello, playground"
struct FilledButton: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration
.label
.foregroundColor(configuration.isPressed ? .gray : .white)
.padding()
.background(Color.accentColor)
.cornerRadius(8)
}
}
struct RootView: View {
var body: some View {
VStack {
Button(action: {
print("Button 1 tapped")
}) {
Text("Butt 1")
}
.buttonStyle(FilledButton())
}
}
}
PlaygroundPage.current.setLiveView(RootView())
import UIKit
import SwiftUI
import PlaygroundSupport
var str = "Hello, playground"
extension NumberFormatter {
static var currency: NumberFormatter {
let formatter = NumberFormatter()
formatter.numberStyle = .currency
return formatter
}
}
struct SuperCustomTextFieldStyle: TextFieldStyle {
func _body(configuration: TextField<_Label>) -> some View {
configuration
.padding()
.border(Color.accentColor)
}
}
struct ContentView: View {
@State private var text = ""
@State private var price = 99
var body: some View {
TextField("type something...", text: $text)
.textFieldStyle(SuperCustomTextFieldStyle())
.padding()
}
}
PlaygroundPage.current.setLiveView(ContentView())