简体   繁体   中英

How to add a focus ring to TextEditor in SwiftUI for MacOS

In contrast to TextField which has an animated blue focus ring, the TextEditor control doesn't have it. How can this be added? It should look and behave (ie animations) exactly like the one from TextField, so just adding a border isn't enough.

在此处输入图像描述

By using something like Introspect , you could do:

struct TextEditorWithFocusRing: View {

    @Binding var text: String

    var body: some View {
        TextEditor(text: $text)
            .introspectTextView { textView in
                textView.enclosingScrollView?.focusRingType = .exterior
            }
        }
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM