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
import SwiftUI | |
struct ExampleView: View { | |
var body: some View { | |
VStack(alignment: .center, spacing: 16) { | |
Text("One") | |
Text("Two") | |
Text("Three (override parent modifier)").font(.headline) | |
Text("Four") | |
} |
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
import SwiftUI | |
struct ExampleView: View { | |
var body: some View { | |
Text("Hello world!") | |
.foregroundColor(.blue) | |
.foregroundColor(.black) | |
} | |
} |
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
import SwiftUI | |
struct MyButtonStyle: ButtonStyle { | |
func makeBody(configuration: Configuration) -> some View { | |
configuration.label | |
.fixedSize() | |
// apply size modifiers | |
.frame(width: nil, height: 48) |
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
import SwiftUI | |
struct MyButtonStyle: ButtonStyle { | |
func makeBody(configuration: Configuration) -> some View { | |
configuration.label | |
.fixedSize() | |
// apply background color BEFORE size modifiers | |
.background(Color.blue) |
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
import SwiftUI | |
// UIView wrapped with SwiftUI | |
struct UserAvatars: UIViewRepresentable { | |
let users: [UserProfile] | |
func makeUIView(context: Context) -> UserAvatarsUIView { | |
return UserAvatarsUIView() | |
} |
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
import SwiftUI | |
import UIKit | |
class MyViewController: UIViewController { | |
// this is how you embed a SwiftUI View | |
lazy var host: UIViewController = { | |
return UIHostingController(rootView: MySwiftUIView()) | |
}() | |