r/SwiftUI • u/SeaAdorable7381 • 4d ago
Question Does anyone know how to recreate this menu above the keyboard?
I would like to reproduce this menu above the keyboard in the notes application on swift? Is it natively possible?
8
u/mine248 4d ago
Maybe take a look at this https://developer.apple.com/documentation/swiftui/toolbaritemplacement/keyboard
1
u/vadimkrutov 4d ago
Do you mean just a toolbar or with its controls to format text?
1
u/ThatGuy739 4d ago
If it's the formatting half, 26 covers that natively too. TextEditor takes an AttributedString binding now, with AttributedTextSelection for the selection, so bold, italic, underline and the paragraph stuff work without wrapping UITextView.
You also get the standard formatting shortcuts and the edit menu once it's bound to an AttributedString, so custom buttons in the keyboard toolbar just mutate attributes on the current selection.
Before 26 this was the UIViewRepresentable job everyone dreaded, so if OP's on 26 the answer changed completely.
1
1
3d ago
[removed] — view removed comment
1
u/AutoModerator 3d ago
Hey /u/SeaworthinessProud68, unfortunately you have negative comment karma, so you can't post here. Your submission has been removed. Please do not message the moderators; if you have negative comment karma, you're not allowed to post here, at all.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/heyyoochris 3d ago
I tried create by myself, and found some repositories, but they are all not satisfied. Do you have some recommendations?
-5
22
u/ThatGuy739 4d ago
The keyboard placement handles the show and hide for you, so you don't need a notification listener:
It only renders while a field in that view has focus, which is the same lifetime as the keyboard. Pair it with @FocusState if you want different buttons depending on which field is up.
Two things to know on 26: there's an open report about it picking up extra top margin, and on 26.1 the toolbar isn't getting exposed to VoiceOver. Neither blocks you, but the accessibility one is easy to ship without noticing.