Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there anyway to style or change color of background of keyboard toolbar in SwiftUI

Tags:

xcode

ios

swiftui

I am presenting a toolbar on top of my keyboard to dismiss the keyboard using the following modifier:

.toolbar {
        ToolbarItemGroup(placement: .keyboard) {
            Spacer()
            Button {
                UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
            } label: {
                Image(systemName: "keyboard.chevron.compact.down.fill")
            }
        }
    }

Is there anyway to change the color of the toolbar background and maybe give it upper right and upper left corner radius? So far I can only change the color of the symbol or text that I add to the toolbar but not the toolbar background itself.

enter image description here

like image 508
alionthego Avatar asked Oct 24 '25 14:10

alionthego


1 Answers

You could also just create a view of fixed length that lies at the bottom of the ToolbarItemGroup.

(Using maxWidth will not work for some reason.)

.toolbar {
      ToolbarItemGroup(placement: .keyboard) {
            Text("save")
                .frame(width: UIScreen.main.bounds.width)
                .frame(height: 45)
                .background {
                    RoundedRectangle(cornerRadius: 10)
                        .fill(Color.customWhite.opacity(0.1))
            }
      }
}
like image 59
Plato Avatar answered Oct 27 '25 05:10

Plato