Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function as a template for SwiftUI elements

Tags:

swiftui

I would like to use this function as a template with immutable values in a SwiftUI layout but get the error Result of call to 'padding' is unused:

func keys (padding: CGFloat, text: String, color: Color?) {
    Rectangle()
        .foregroundColor(color)
        .padding(.trailing, padding)
        .padding(.leading, padding)

    Text(text)
        .font(.largeTitle)
        .foregroundColor(.white)
}

Thanks for any help.

like image 420
Daniel Avatar asked Aug 02 '26 21:08

Daniel


1 Answers

Here it is

func keys (padding: CGFloat, text: String, color: Color?) -> some View {
    Group {             // << or any other container you want
        Rectangle()
            .foregroundColor(color)
            .padding(.trailing, padding)
            .padding(.leading, padding)

        Text(text)
            .font(.largeTitle)
            .foregroundColor(.white)
    }
}
like image 83
Asperi Avatar answered Aug 05 '26 17:08

Asperi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!