A basic functionality I am trying to implement in UITextView.
I have a text (NSString) and I am trying to place in to the text field as a paragraph (indentation). Is it possible? I have seen many links but none of them have an exact answer.
We have a property named textAlignment but it is for left, right or center not indention.
Can anyone suggest how to implement this?
You should consider using a UIWebView if your displayed text has formatting. Using textViews and labels quickly renders the code to complex.
Possible solution in this post - as the first answer suggested, use a UIWebView.
Related
I want to set 2 different fonts within the same UITextField and UITextView . How to do it?
Its a bit of work - you'll need to use Core Text and NSAttributedString to do this.
There are plenty of tutorials and examples, although I'd suggest using someone else's already-made UILabel subclass such as:
OHAttributedLabel
or
TTAttributedLabel
As these usually have some convenience methods to make handling a lot easier.
I would do it with 2 custom textfields overlaying, both backgroundcolor:clearColor, maybe stuffed on an image that represents the background.
I don't think it is possible to handle 2 different fonts within the same UITextField or UITextView. If you want to have different font style you can either set different font style within a UIWebView or use the coreText API.
Here are some links that might help:
iPhone Development - Setting UIWebView font
the official doc on core text: https://developer.apple.com/library/mac/#documentation/StringsTextFonts/Conceptual/CoreText_Programming/Introduction/Introduction.html
I know you already picked a valid answer but... don't do it that way... it's not worth it. Use a webview instead and draw everything with html.
In interface builder change Text View's Text field to Attributed. In that small editor that appears you can change the font/format/color of the selected text, like in any advanced text editor.
How can you create a UITextView that can have images inline? I looked up NSAttributedString, but it seems iOS does not support image attachments. Any ideas for an editable text view that can display images (I suppose RTF would do this)?
Thanks in advance for your help!
The only method I am aware of is to use a UIWebView. There is no way to add images to a UITextView, unfortunately, just plain text.
You could use the NSTextAttachment class. It lets you insert images inline of text.
I found an example of this in a cool project here: https://github.com/dzog/ImgGlyph. ImgGlyph provides UITextView and UILabel subclass implementations that help you replace specific strings with images and ensures they're sized correctly with respect to the text surrounding it.
Im using CoreText to display some text, creating framesetter, frames and so, and everything is fine. I can even format the text, but this all is done before I draw. Now the question that is driving me crazy:
CoreText is just to render text? I cannot get any reference to CTRuns or Glyphs to highlight them?
Another sub big question, the Pages App dont use CoreText, anyone knows? In Pages, you can select any already drawn styled text!
All I want is to draw the text and be able to let the user tap to select any text or doubleTap to select the paragraph.
Please, anyone, any light?
Thanks in advance.
CoreText is just to render text. Implementing user interaction is quite another matter. You need to implement UITextInput protocol, see here. It's a big job.
If you just want to input text and don't have a need for advanced typography, just use UITextView or UIWebView.
you can get image bounds of CTLines and CRRuns via core text here is little example i made for my app it's not perfect yet but you can get a little idea of how it works.
textViewProject
What I am trying to do is create tooltip functionality so that certain words in my instructional app can be tapped and the definition pops up. For the popup part I plan on using code from “AFInformationView” which provides bubbles on the iPhone.
The part I'm struggling with is how to associate A particular word's location with the bubble. Currently I have the text on a UILabel that is on a custom UITableCell. Since I calculate the row height on the fly with:
[textToUse sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:CGSizeMake(stop-start, 500)];
I'm not sure what the coordinates for a specific word will be. I was thinking that if I created a custom DataDetectorType that could be the fix.
If anyone knows how to do this or has any other ideas I would be happy to hear them.
Thanks,
Andrew
I didn't create a custom UIDataDetectorTypes but Craig Hockenberry did something like it with his TwitterrificTouch.
He uses regular expressions to detect links and other things. I provide it with my keywords and then they become tappable. He places buttons on top of the matching text from the underlying labels. You can google a lot of posts that talk about "putting transparent buttons on top" of various things but Craig's code is the only example/working code I could find.
Here is the link:
http://furbo.org/2008/10/07/fancy-uilabels/
I don't think this is possible. The (few) Data Detector types that the iPhone currently supports are hard-coded with a integer type id. There does not seem to be a mechanism to extends that list of types.
File a feature request in their bug tracker. I will do the same.
AFAIK, you can't create custom data detectors.
The best approach for this sort of thing seems to be using UIWebViews. At least that's what I did. However, you shouldn't use a UIWebView inside a UITableViewCell. In fact, no subview of a UITableViewCell should respond to user input. So I think the best approach would be to display a UIWebView when the cell is tapped.
UIWebViews could be a possible approach but on scrolling you should consider that the whole text should be parsed to detect the words.You could use HTMl tags to make them blue and provide the links.But how could i then assign a custom behavior then opening in safari?
If you want custom data detector you could write an extractor method to primarly patch the links with help of NSregularExpression. For example
NSString regex = #"(http|https|fb)://((\w)|([0-9]*)|([-|_]))+(\.|/)"; to patch alll the links including Facebook URLs inside text like fb://friends.
Then you could use NSattributedString yo mark the links with different colors etc.
ThreeTwenty has a great library called TTTAttributedLabel where you could assign links to certain parts of a text. I also scrolls quite fast if you use it in tableviews
https://github.com/mattt/TTTAttributedLabel
I'm developing an application for the iPhone where some text is shown in a UITextView. I want to search for a specific word in the text and then show the text with that specific word colored. If anyone can help me solve this, I'll be very glad.
UITextView does not allow any formatting of the text within it. If the text is static (i.e. doesn't need to be edited), use a UIWebView instead; that will allow you to apply HTML formatting.
If a web view isn't an option, your best bet will be to try to calculate where the text in question will fall in the text view and then draw some sort of highlight around it. NSString has some methods to calculate how much space you need to draw a given string on screen; by being very, very clever with those methods, you may be able to work out where the word you're trying to highlight is. Unfortunately, this will not be at all simple.
If you do come up with a solution, everyone here would probably love to hear about it!