Ensuring the symbol th in iOS appears correctly - ios

I need to have 19th century in my UILabel. But it should appear as 19th century where the th symbol is a superscript. I am entering the label using plist. How do I ensure that it appears correctly in UI?
Need some guidance on this.
Image attached:

Use Unicode characters ᵗ (U+1D57) and ʰ (U+02B0).
You can enter these literally as:
NSString *num = #"19 ᵗʰ";
or:
NSString *num = #"19\u1d57\u02b0";
If those don't look nice enough, using an NSAttributedString would be best.

NSAttributedString has a property for that on osx, so perhaps it will be available on ios7. for now you could either store html in your plist and display that, or store 2 strings '19' and 'th' and manually add two uilabels into the top level one and manually layout them to create the superscript effect.

Related

Some Urdu characters not rendering correctly on UITextView

I faced an issue with rendering Urdu on UITextView. I have used NSAttributedString to render text, but some characters are not appearing well using Jameel-Noori-Nastaleeq styled Regular and AlviLahoriNastaleeqfont. You can see in first picture how a character on the second line is not correctly rendered
Here is another reference screenshot, please see lines 5 and 13 where some characters are not rendered correctly.
What I have Tried
1-
There are some characters that do not appear well i.e. ["بڑ", "ئز", "یز", "ڈ", "ز"] I
tried to find all the occurrences of these characters using this tutorial [Find and Return the Ranges of All the Occurrences of a Given String in Swift][3]
Then change the font of all these occurrences to Jameel-Noori-Nastaleeq-Kasheeda because this little change will not impact overall looking, but finding all occurrences of a single character in a string does not work well in urdu, but only the case when we find the first occurrence this will work well using string.range(of: "ئز").
I have tested finding all occurrences of a substring in English that work well using the above tutorial method.
.
[3]: https://betterprogramming.pub/find-and-return-the-ranges-of-all-the-occurrences-of-a-given-string-in-swift-2a2015907a0e
2- Text is rendered well with Jameel-Noori-Nastaleeq-Kasheeda, but I have to use Jameel-Noori-Nastaleeq styled Regular
Is there any workaround that displays all characters well for Urdu in Jameel-Noori-Nastaleeq styled Regular.
Finally get solved, use UILabel instead of UITextView
Actually, UILabel renders Jameel Noori Nastaleeq without any issue but in the same context, UITextView causes issues.
According to my experience, issue is with UITextView compatibility with Jameel-Noori-Nastaleeq and AlviLahoriNastaleeq also Apple should see into this issue.

how to prevent iOS from converting ascii into emoji?

I have this simple String applied to a UILabel
labelInfo.text = "(11) ♥ 6"
this is how I need it to look like
(11) ♥ 6
this is how it looks like instead
I really searched alot, and didn't find a way to do this..
I found ways to remove emojis, but this makes it look like this
(11) 6
if you have a hint, it will be very appreciated.
Apple has changed this in iOS 5. In most fonts, all characters that can be potentially displayed as an emoji are replaced with the colorful character from the Apple Emoji Font.
There are several solutions:
Use the Unicode variant selector for non-coloured glyph: U+FE0E
labelInfo.text = "(11) \u{2665}\u{fe0e} 6"
Set a font where Apple doesn't force emojis. People usually recommend Hiragino Mincho ProN.
Use the graphics contexts drawing method to display the text.
Also see:
Unicode characters being drawn differently in iOS5
Prevent Emoji Characters from Showing
iOS 5 upgrade changed font appearance
Go to Edit->Emoji and Symbols in Xcode.Type the name of symbol you want to use(in your case heart).Copy it.Then paste it the way you want. Eg:_mylabel.text=#"♥︎";
This worked for me:
Please make sure to use the actual ASCII symbol instead of code and append \u{0000FE0E} after it like shown below:
label.text = "♥\u{0000FE0E} Love!"
It will show up in label correctly like this:
♥ Love!
Note: Please make sure that the symbol exists in your font. In case it does not work, please try changing the font. Thank you.

Circled Latin Capital Letter M on iOS [duplicate]

I would like to get a down arrow to display inside a UILabel. Specifically ⬇ Unicode: U+2B07. This is show sort order on a column header.
I have seen the code to get unicode characters to display and when I use it for the symbol above it doesn't display as expected but rather comes up with a blue down arrow with gloss.
Has anyone seen this?
Displaying some characters as "Emojis" is a feature which is e.g. (controversially) discussed here: https://devforums.apple.com/message/487463#487463 (requires Apple Developer login). This feature was introduced in iOS 6.
A solution (from https://stackoverflow.com/a/13836045/1187415) is to append the Unicode "Variation selector" U+FE0E, e.g.
self.myLabel.text = #"\u2B07\uFE0E";
// or:
self.myLabel.text = #"⬇\uFE0E";
Note that on iOS <= 5.x, the Variation selector is not necessary and must not be used, because iOS 5 would display it as a box.
In Swift it would be
myLabel.text = "⬇\u{FE0E}"
If you're seeing the blue arrow with gloss, you have the right character, but it's showing one of the emoji-style characters. Try changing the font of your UILabel to something like Arial Unicode MS.
Edit After a little testing, it looks like changing the font doesn't actually work. It keeps displaying the glossy arrow. It's probably better to go with the suggestion of the other answer and use a different glyph, like \u2193, which does work:
[nameLabel setText:#"\u2193"];

How to highlight multiple text fragments on iOS?

The past few days, I have been searching for a suitable solution to highlight multiple text fragments on iOS. The general idea is similar to how text highlighting works in Amazon's Kindle application.
I have experimented with UITextView as well as UIWebView, but I haven't find the right solution in terms of usability and performance.
The idea is simple. The user taps a sentence and the sentence is highlighted. When another sentence is tapped, that sentence is highlighted as well. The built-in solution for highlighting text is not suitable for this purpose. An important aspect of the solution is that the text needs to be styled, which is possible with UITextView since iOS 6.
My question is fairly general, that is, what are some viable approaches to implement this type of functionality? Are there any open source solutions that do what I describe?
I will suggest you to NSAttributedString on multiline UILabels. Starting from iOS 6 UILabels by default supports attributed strings without any modifications.
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:#"Some text and some more %#", dynamicString]];
//Change background color to highlight a sentence, by giving sentence's range
[str addAttribute:NSBackgroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(sentenceStartIndex, sentenceLength)];
[label setAttributedText:str];
EDIT: It turns out UITextViews also support NSAttributedString I didn't try that, so you may replace UILabels with UITextViews.
I recommend using TTTAttributedLabel from Matt Thompson. It supports attributed strings, works all the way back to iOS 4, and is MIT licensed.

iOS5 fancy icons (emoji?) for special unicode chars - not what I want

I've always thought it was great that I could use simple iconic unicode characters in a string when I needed an arrow or a bullet or whatever. The glyphs would render in the same color as the rest of the string with a nice simple and clean icons. I could preview how they'd look by using the Mac's "Special Characters" dialog on the Edit menu in XCode.
In iOS5, these glyphs render in full color and aren't simple and clean. I believe these are Emoji icons?
I'm looking for an explanation of this change, and ideally how to force iOS5 to revert to the iOS2 - iOS4 behavior.
Here's an example: #"← left arrow, right arrow → airplane ✈";
Edit:
Apparently the NSString UIKit extensions for rendering text (drawAtPoint: / drawInRect:) don't exhibit this behavior. So perhaps it is a UILabel thing? Specifically I've noticed it inside a UISegmentControl segment button, and in a UILabel.
This isn't a bug, it's down to the font used. When you use a character in a string that isn't available in the chosen font, iOS automatically substitutes a glyph from another font.
The system font (Helvetica) doesn't have those characters in it, so I'm guessing that Apple have have changed the list of fallback fonts so that Emoji ranks above whatever it was using previously for the fallback for those characters.
To fix it, find a font that a) has the version of the characters you want in it, and b) is available on iPhone, and set your label to use that instead of the default system font.
Alternatively, you could just make a UILabel subclass and override the drawRect method so it uses the drawAtPoint/drawInRect methods to draw the string.

Resources