Skip to content
Discussion options

You must be logged in to vote

We don't support using @ViewBuilder as a property of views, but you can use a closure returning a View instead. E.g.:

struct RedBorderView<V: View> : View {
    let content: () -> V

    var body: some View {
        content()
            .border(Color.red, width: 5.0)
    }
}

And then call:

RedBorderView {
    Text("Hello Red!")
}

Hopefully that is sufficient for your needs. If not, please let us know.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Louis-PAGNIER
Comment options

@aabewhite
Comment options

@Louis-PAGNIER
Comment options

Answer selected by marcprux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants