Scrollability without Editability inside a UITextField - ios

I want to use UITextFields for inputting relatively small amounts of text. The text can be longer than the size of the text field, and I want the user to be able to touch/scroll inside the text field in order to be able to read all of it.
This type of semi-scroll-like behavior is available in edit mode, but I don't want the user to be able to edit, just scroll. The keyboard shouldn't come up in other words. (I do allow the user to do editing, but that's in another section of the app.)
I'm suspecting that UITextField wasn't built to do what I'm trying to do and that I should go explore the capabilities of UITextView instead. Since I've already made a fair investment in providing the infrastructure to support UITextField editing (when it's needed, just not in the current circumstances), I'm a bit reluctant to abandon UITextFields altogether.
Does anyone see a way of doing what I want to be able to do?
Howard

y dont u use UITextView instead of textfield with small size

Use a scroll view with the UILabel as the subview of the scroll view?
Alternatively, use a UITextView and set its editable property to NO. If you are worried about the styling of the textview, use the plain style and customized with other UI elements.

Related

Inline button and/or textfield within string which wraps the same as text using Swift

This is more of a question of how to go about achieving it rather than a specific solution. I would like to have a label which allowed buttons and textfields to be inline and wrap to the next line. An example is the iOS shortcuts app where you can type in the same block as the text, and the textfield wraps along the same line. It is a textfield as there is a caret.
At a highlevel it might look something like this:
where each view follows the line and wraps to the next when needed.
I originally thought about using an NSAttributedString with links that were styled and the link could either act as a button, or open a textfield for input. I tried this and got something which worked but it did not resemble the iOS shortcuts app where the textfield is within the text. I have also thought about using textkit, but I have not gotten that far with this as I am not sure it is the correct approach.
Thank you for any ideas or solutions.
EDIT
I have thought about another way of achieving this but I don't know whether it would work either. The idea would be to use a collectionView of textfields. Some textfields would share the same LayoutManager so that the text is shared across the textfields. I would have to calculate how many textfields to create so that they flowed down the collectionView
In the image, Label 1 is made up of 1 textfield which has editing disabled. TextField 1 is made up of 3 textfields which have editing enabled and the three textfields would share the same LayoutManager. Label 2 is made up of 2 textfields with a shared layout manager, but editing disabled.
Using this approach would mean calculating how many textfields to create for each "Block" (Label or TextField) and updating this each time content changes. With this approach, I am only thinking of labels and textfields but the button can be added at another time.
I just started on this, but realised that sharing layout managers disables editing so I don't know whether this would be possible anymore.
Thanks
This is non trivial task for sure, and I don't think there's a ready-for-use solution.
Using NSLayoutManager you can calculate frames of each line/character of your text, and then forbid touches depending on these frames, and add background under editable text.
You have to use UITextView, because you gonna need to forbid user to select part of the text, and you can do it using something like willChangeSelectionFromCharacterRange:toCharacterRange: delegate method, and ofc you need shouldChangeTextIn: to forbid removing non editable text too.

Dynamically Change isAccessibilityElement

I've got a bit of a weird situation. I need to have an element not be read out by VoiceOver when I use the 2 finger swipe method, but to be read when tapping on it still.
The object is part of a TableView cell, and I've given the TableView cell its own accessibilityLabel, because it contains two interactive elements, one of which doesn't actually need to be read when tapped on, so I've disabled its accessibility property.
However, my other one needs to be read still when tapped on. The issue is, it's already being read as part of the cell's accessibilityLabel, and then it is read again because it is still an accessible element. Is there any way to differentiate between why VoiceOver is reading an element? Or to dynamically change the accessibilityLabel?
You can dynamically change accessibilityLabel simply by assigning it or overriding the method on the accessible view. However, you shouldn't rely on VoiceOver respecting the change in real time.
Users can navigate via tap or swipe and expect elements to persist regardless of how they were reached. In general, I discourage clever solutions that assume how users interact with VoiceOver.
I'd encourage you to either override the cell summary to omit the label or disable accessibility on the label and leave the content in the cell summary.

How to click on a word and have a pop-up window come up in iOS

First off, thank you very much for taking some time to help me out.
I am rather new to iOS development and need some assistance on how to be able to enter text into a UITextField and then be able to tap a word and then have a pop-up screen come up. I am going to have the pop-up screen designate what highlight color the text is and I know how to go about doing that using
#property(nonatomic, retain) UIColor *highlightedTextColor
I am not sure how to make each word register individually and then be able to tap it and have the pop-up come up. Thank you all for any help that you can aid me with.
Have a great day! :)
This is a tough problem, but I think I have a solution that would accomplish what you need functionally, but I don't fully know your design constraints so your mileage may vary.
Create a UICollectionView with a layout that will flow across lines but always align items to the left. You can get a UICollectionViewFlowLayout subclass to do this with not much work. This should be able to be styled to approximate the look of a UITextField to a degree.
Create a hidden UITextField.
When the user goes to enter input, make the hidden textField the first responder. This is just a container for their input.
As the user types, parse the text in the UITextField into word components by splitting the string on the ' ' character. Each word will be represented in the UICollectionView as one cell.
Implement the UICollectionViewDelegate method for cell selection. When the cell is selected, display your color picker pop up, set some color information to recreate the cell with the same color later on.
With this approach you won't have the typical editing tools like tapping words, moving your cursor, etc. You will have deletion, however.

Placing UIView or UILabel inside UITextField or UITextView acting like character

I need to create a dialog, similar to the one that is used to write functions in Numbers from APple, for example.
User can select range in the table, which is then represented as any kind of UIView inside text input line. When long-tapped, the content can be edited like normal text, but what is most important is that whole subView, containing text with range description is treated as one character.
Does anybody know or have idea how to achieve this?
I would appreciate any hints...
I had to deal with something similar, to have custom UIView(s) in a search field.
I'm not aware of a "simple" way (ie, API) to achieve your goal. You need to create a custom component that looks like a classic field, but isn't one.
To be a little more specific:
Subclass an UIView (or directly an UIScrollView)
Have inside a TextField (or UITextView depending if it needs more than one line) to handle the "keyboard".
Put some custom UIView/UILabel before the textField/textView and adjust the textField/textView origin depending these views/labels
If you want to have a label/view IN the text, then it's a little more complex and you'll need something even more custom:
Handling the keyboard events without a textField/textView (there is a way but I forgot how exactly)
Drawing the text and adding views/labels in specific locations.
Of course all depends on the component you want to create ^^ there is no one simple answer.

Search UITextView for a specific word in iOS app

I have added UITextView to an app and the list is kind of long. What is the easy way of searching a word in this list. I can add a button and textfield to enter and search for a word. I was was wondering maybe there is already built feature for UITextView.
Thanks very much
[TextView.text rangeOfString:]; or something like this.
It sounds like you're asking if there's a search UI built-in for UITextView (like the way the system libraries manage some aspects of the searchDisplayController property on UIViewController). There is not a built-in feature for this.
One convenient option you might consider is creating a 44 pixel tall view with your search text field and button(s) and then set this view as the "inputAccessoryView" on the UITextView object. The system will then manage animating its display above the keyboard, and scrolling the UITextView so the user is not typing underneath this view.

Resources