I want a text field similar to the stock messaging app in the iPhone. Text field should have the same look and should be expandable to allow multi-line editing. Could you please suggest a method to get this in my app?
Thanks.
Use a UITextField.
To get the height of the text field use -sizeWithFont:constrainedToSize:lineBreakMode:.
To have the look of the Apple's text field put an image behind the text field that looks like Apple's text field. See -resizableImageWithCapInsets: to get the image to stretch properly.
Have a look at this :
UIBubbleTableView
EDIT :
The previous link was for the "bubble styled" tableview. If you want the view where you actually type the message, this is the one :
HPGrowingTextView
For other people who are searching for libraries but the ones mentioned here are with many bugs
Here is a library:
SlackTextViewController
A drop-in UIViewController subclass with a growing text input view and other useful messaging features. Meant to be a replacement for UITableViewController & UICollectionViewController.
Related
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.
I am trying to incorporate a similar kind of view in an app. So, was wondering if its a tableview or something else?(see attached image) I am very new to learning swift and would greatly appreciate if someone could help me identify how this kind of structure can be made. Just the name of the element to be used would be enough. I will look up the details on Apple Docs.
It is a customized UIPickerView with two components. Just like the default Date Picker in iOS.
These questions should help you in styling the UIPickerView:
How can I change text font in picker in iOS 7?
Custom UIPickerView with Custom Background color
For that last question, please take a look at DShah' answer.
Addition to Nina's answer, below are some of the good custom Picker view controls which will be good to use in terms of performance and customizable.
http://www.cocoacontrols.com/platforms/ios/controls/cppickerview
http://www.cocoacontrols.com/platforms/ios/controls/afpickerview
http://www.cocoacontrols.com/platforms/ios/controls/v8horizontalpickerview (Horizontal PickerView)
Scenario: I have a list of medication (stored somewhere, let's say an NSArray).
There is a UITextField where a user can enter a medication to get more information about it (or whatever).
I want to suggest word completions while he is typing (but that is rather easy).
Where is the best place to show these suggestions? Since it's on the iPad i want it kinda like when you google and you get your suggestions right below the search bar. Is that possible on the iPad? A table that lays over the rest of the screen, placed below the text field? Like a pop up or something? I have never really used an iPad in my life before, therefore I don't know what the iOS way would be..
Edit: Something like this but connected to a textfield and not a button or whatever that thing is:
Edit: Or even better: Something like this but for iPad and not Android:
In my app I used a UITableView for displaying the suggestion.
I added the tableView above my UITextField. When there is no auto complete word found, I hide the tableView.
Please check my autocomplete implemetation.
Check out my control, MLPAutoCompleteTextField for iOS. It is a subclass of UITextField that does autocomplete.
The implementation is similar to what you are looking for in the second screenshot, and very customizable.
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.
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.