I am using a UITextView to display arbitrary NSStrings, with various font sizes (depending on the length of the string, and the screen resolution of the device). My problem is that the UITextView seems to display these little "underscore like" characters, instead of spaces, if the space character is the first character on a newline (after the text has been wrapped). Anyone know a way to turn this off?
OK, I think this was a problem with the font I was using. Also possibly the text size of the font was important. Perhaps the fact that I was displaying in italic was the thing. Anyhow, now that I have a different font, different size, not italic, I haven't noticed this problem.
Related
I want to add the ascii artwork functionality into my existing Emoji App. I have seen some applications on the appstore, which displayed the ASCII Artwork. I donot have any idea from where i should start. Please help me in adding this functionality.
You need to pick a monospaced font so that the ascii art is displayed properly. You can check iOSFonts.com for which fonts are supported on the devices you are targeting. To display the ascii art you could use a multiline UILabel (set numberOfLines to 0). A UITextView will work as well but remember that they are editable by default unless you set editable to NO.
Has anyone tried to change the font formatting(bold/italic/color) of a selected word or sentence in a UITextView, like a text editor application? I have been trying to do this but it seems formatting is applied only to the whole text, not on individual words or sentences.
you can change any specific word font, style and size also,
Make UITextView text to "Attributed", by default it was "Plain"
and then you can perform edition on selected text.
UITextView cannot style text fragments. Styles, colors and fonts are applied to the entire text. You may wish to use a UIWebView or Core Text to render your text instead.
I have a problem about the font in iphone/ipad
Everyone knows UILabel can't do rich text.
So I choose FrontLabel http://github.com/zynga/FontLabel/blob/master/README
I guess what FrontLabel is doing is something like NSAttributedString and core text framework, and also, it is quite low level. But anyway, I have a problem.
If I want to display a mixed language text, let's say English + Chinese, and give the whole string a font of "ArialMT", then all Chinese characters are displayed like small squares.
I have tried, if I assign "STHeitiTC-Light" font to the text, no problem, both Chinese and English can be displayed, because STHeitiTC-Light is a Chinese font in iphone/ipad.
I think FrontLabel can't automatically select best font for non-latin text if the given font does not apply.
If I use UILabel and assign it as "ArialMT", and let it display text of Chinese or Japanese, NO problem, right? I guess apple is detecting font for different language?
Please give me some clues how can I solve this problem if I want to use FrontLabel?
Thanks
author of FontLabel here.
You're right, FontLabel does not do automatic font fallback if the glyph cannot be found in the selected font. Implementing such a behavior was outside the scope of the project, as it can be quite complex. UILabel does perform this, as it uses WebKit to do the actual text rendering and WebKit supports font fallback. I am unsure if CoreText provides this or if it behaves like FontLabel. In any case, if you need multiple fonts in FontLabel, you can specify different fonts for different ranges of your ZAttributedString. Unfortunately there's no easy way to determine which ranges are necessary without inspecting your string directly. If you know you're only working with English and Chinese, you could iterate over the characters in your string to determine if they're likely to be english or chinese characters, and use that to determine which ranges to assign fonts to. The alternative would be to teach FontLabel how to perform font fallback, but as I said before, that's quite complicated.
Alternatively, if you're comfortable require 4.0 or above on iPhone, you can try using CoreText. As I said before, I'm unsure if it does font fallback, but it's worth investigating.
I have spent a few days trying to get around the limitations with UITextField, namely no text wrap and number of lines. I have created a UILabel, which is used to display the text entered in UITextField and does all the formatting stuff properly. The UITextField is hidden and the user sees all the text entered only in UILabel as it's being entered.
Everything is working perfectly except for the lack of a cursor on the UILabel to show the user where the next character typed into the field will show up.
I have experimented with using various characters as cursors on the label. But there is no getting around the fact that it is not the standard blinking cursor indicator on the iPhone and so the whole thing just looks wrong.
Before I abandon ship and go for a UITextView (with its own set of issues) I was wondering if anyone has any ideas as to how a blinking cursor can be added to the text field on a label text.
Thanks in advance.
Your approach has other issues which make it worth rethinking the strategy.
How does selection look like?
copy + paste?
Do you handle right to left languages?
Auto correction?
The list is certainly longer, but I think it's enough to consider other solutions. But I agree that all of UIKit's text handling is a bit poor.
If you don't need to support selection, copy and paste, and only need multiline input, you could use a | character and animate it as if it were blinking... either that or perhaps a custom overlay view on top of the label, that would implement the cursor drawing, animation and positioning based on the length of the string and the font used.
– sizeWithFont:forWidth:lineBreakMode:
– sizeWithFont:constrainedToSize:
– sizeWithFont:constrainedToSize:lineBreakMode:
– sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:
may help to achieve just that.
So what are the issues preventing you from going to a UITextView? It seems possibly easier to address those.
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!