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 | |
/// Common image aspect ratios | |
public enum AspectRatio: CGFloat { | |
case square = 1 | |
case threeToFour = 0.75 | |
case fourToThree = 1.75 | |
} | |
/// Fit an image to a certain aspect ratio |
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 SimpleSwiftUIView: View { | |
var body: some View { | |
VStack(alignment: .center, spacing: 8) { | |
Text("Heading Base") | |
.headingBase() // internal modifier | |
Button("Primary Button", action: {}) | |
.buttonPrimaryStyle() // internal modifer |
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 UIKit | |
class SimpleUIKitView: UIView { | |
lazy var button: ButtonPrimary = { | |
let button = ButtonPrimary() // internal button class | |
button.title = "Primary Button" | |
button.translatesAutoresizingMaskIntoConstraints = false | |
return button | |
}() |
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
SwiftUI | Lines of Code | UIKit Equivalent | Lines of Code | |
---|---|---|---|---|
.headingBase() | 43 | LabelHeadingBase() | 366 | |
.primaryButtonStyle() | 188 | ButtonPrimary() | 792 |
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 | |
@available(iOS 14.0, *) | |
struct ExampleSwiftUIView: View { | |
var body: some View { | |
ScrollView { | |
LazyVStack { | |
ForEach(1...50, id: \.self) { | |
Text("Row \($0)") | |
} |
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
enum ButtonType: String, CaseIterable, Identifiable { | |
case primary | |
case secondary | |
case link | |
case overlay | |
} | |
// View usage | |
Picker(selection: $selectedButtonType, label: Text("Select a button type")) { |
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 | |
import UIKit | |
class MyViewController: UIViewController { | |
// this is how you embed a SwiftUI View | |
lazy var host: UIViewController = { | |
return UIHostingController(rootView: MySwiftUIView()) | |
}() | |
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 | |
// UIView wrapped with SwiftUI | |
struct UserAvatars: UIViewRepresentable { | |
let users: [UserProfile] | |
func makeUIView(context: Context) -> UserAvatarsUIView { | |
return UserAvatarsUIView() | |
} |
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 MyButtonStyle: ButtonStyle { | |
func makeBody(configuration: Configuration) -> some View { | |
configuration.label | |
.fixedSize() | |
// apply background color BEFORE size modifiers | |
.background(Color.blue) |
OlderNewer