Skip to content

Instantly share code, notes, and snippets.

@laevandus
Last active August 30, 2020 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laevandus/4f4df2f88f56bdbc2bff13f754682b8a to your computer and use it in GitHub Desktop.
Save laevandus/4f4df2f88f56bdbc2bff13f754682b8a to your computer and use it in GitHub Desktop.
struct ContentView: View {
@State private var textMinWidth: CGFloat?
var body: some View {
VStack(spacing: 16) {
TextBubble(text: "First", minTextWidth: $textMinWidth)
TextBubble(text: "Second longer", minTextWidth: $textMinWidth)
}
}
}
struct TextBubble: View {
let text: String
let minTextWidth: Binding<CGFloat?>
var body: some View {
Text(text).equalWidth(minTextWidth) // custom view modifier
.foregroundColor(Color.white)
.padding()
.background(Color.blue)
.cornerRadius(8)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment