Forked from vincefried/SimpleRepresentable.swift
Last active
September 8, 2023 07:12
-
-
Save chriseidhof/cac0515afe0ba0c561f85f6c0f12786b to your computer and use it in GitHub Desktop.
A small demonstration of how I would like a way to modify a wrapped UIView.
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 | |
import SwiftUI | |
struct ContentView2: View { | |
var body: some View { | |
VStack { | |
SimpleRepresentable(text: "Test") | |
} | |
} | |
} | |
struct SimpleRepresentable: View { | |
var text: String | |
var minimumScaleFactor: Double = 0.1 | |
var backgroundColor: Color = .blue | |
var body: some View { | |
_SimpleRepresentable(parent: self) | |
.padding() | |
.background(backgroundColor) | |
} | |
} | |
fileprivate struct _SimpleRepresentable: UIViewRepresentable { | |
let parent: SimpleRepresentable | |
func makeUIView(context: Context) -> UILabel { | |
let label = UILabel() | |
label.text = parent.text | |
label.minimumScaleFactor = parent.minimumScaleFactor | |
return label | |
} | |
func updateUIView(_ uiView: UILabel, context: Context) { | |
uiView.text = parent.text | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment