Post

Replies

Boosts

Views

Activity

How do I size a UITextView with scroll disabled?
tl;dr: UITextView does not auto layout when isScrollEnabled = false I have a screen with multiple UITextViews on it, contained within a ScrollView. For each textview, I calculate the height needed to display the entire content in SwiftUI and set it using the .frame(width:height:) modifier. The UITextView will respect the size passed in and layout within the container, but since UITextView is embedded within a UIScrollView, when a user attempts to scroll on the page, often they will scroll within a UITextView block rather than the page. They currently need to scroll along the margins outside of the textview to get the proper behavior. Since I am already calculating the height to display the text, I don't want the UITextView to scroll. However, when I set isScrollEnabled = false, the text view displays in a single long line that gets truncated. I have tried Setting various frame/size attributes but that seems to have zero affect on the layout. Embedding the textView within a UIView, and then sizing the container, but then the textView does not display at all. Setting a fixed size textContainer in the layoutManager but did not work. There's a lot of code so I can't copy/paste it all, but generally, it looks like struct SwiftUITextEditor: View { @State var text: AttributedString = "" var body: some View { ZStack { MyTextViewRepresentable(text: $text) } .dynamicallySized(from: $text) } } struct MyTextViewRepresentable: UIViewRepresentable { @Binding var text: AttributedString let textView = UITextView(usingTextLayoutManager: true) func makeUIView(context: Context) -> UITextView { textView.attributedText = text textView.isScrollEnabled = false } ... }
1
0
70
May ’25
"Reveal in Project Navigator" Shortcut Stopped Working
Today after I apparently fat fingered/misclicked/misdragged something in Xcode, the short cut for "Reveal in Project Navigator" (cmd+shift+J) stopped working for me. I don't have any custom shortcut bindings and the other shortcuts still work, as far as I can tell. I've deleted and re-installed Xcode; I've run defaults delete com.apple.dt.Xcode to no avail. I'd really like this shortcut back as it's probably my second or third most used one :(
1
0
218
Mar ’25
Is it possible to get selected text from a Text field?
Basically the title. If a Text field has textSelection enabled, is there anyway to get the text that the user has highlighted? Text("My text here") .textSelection(.enabled) Ultimately, my goal is to be able to highlight text and apply style to individual characters. Using a TextField would give my app the ability to know what's been highlighted, but then I can't style individual elements. I'd like to be able to do this in SwiftUI without having to drop into TextKit. struct MyTextEditorView: View { @State var myText: String = "" @State var textSelection: TextSelection? = nil var body: some View { TextField("Placehodler", text: $myText, selection: $textSelection) } }
3
0
714
Feb ’25