Custom font in SwiftUI's Searchable
Today I learned that you can use prompt
inside TextField to customize its placeholder.
TextField("", text: $authObservable.username, prompt: Text("Email Address").foregroundStyle(Color(.gray)))
So, with this in mind I guess we can do the same with searchable
. Yep, it worked. Now I can set my own custom font.
.searchable(
text: $searchTerm, isPresented: $searchIsFocused,
placement: .navigationBarDrawer(displayMode: .automatic),
prompt: Text("Search for a job")
)
So, I tried to compile it by adding a font()
modifier but it threw a runtime error.
Only unstyled text can be used with init(text:isPresented:prompt:placement:control:)
But, as it turns out setting the font
modifier after searchable
will work.
.searchable(
text: $searchTerm, isPresented: $searchIsFocused,
placement: .navigationBarDrawer(displayMode: .automatic),
prompt: Text("Search for a job")
).font(OnlineJobsFont.regularFont)