I've searched on the Internet but can't find definite details.
Is there anyway to specify leading and keening for uilabels, textfields or textviews?
I could create custom fonts for each leading and keening pairing but this seems a bit overkill.
There does not appear to be. CoreText offers solutions tho.
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.
Been coding for > 20 years, but there's nothing more humbling than learning a new platform :)
Hopefully I'm not missing something silly, but I can't find a similar issue here or elsewhere on the web.
I have a UI that looks correct in Interface Builder,
but at runtime, the text in the UITextView doesn't seem to wrap, and it doesn't seem to use the font that I've chosen in IB.
I even outputted the font in viewDidLoad at runtime, and it says it's using the correct font, but visually it isn't. All fields (regardless of font selected in IB) seem to display using the default font.
Hoping someone can point out what is likely a newbie mistake, or what else I could do to diagnose.
Thanks in advance
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!