I have a little app which lists the names of certain people from around the world, and some of those names use characters that are not normal ASCII characters, like DÌaz, or ThÈrËse for example.
The strings show up in Xcode just fine, but when I put them in a UILabel, they behave unexpectedly.
My question is: Is there a way to set up a UILabel to to take the exact string in Xcode, and display it properly, even if it is a UTF-8 character (or any other character encoding for that matter)?
UIKit fully supports unicode, your problem is most likely the encoding of the source file. You can set that in the inspector (Xcode 4: ⌘⌥1) under "Text Settings". Make sure it is UTF-8 as well.
Alternative: Use unicode escapes like #"\u2605" (should display ★).
Try to encode the String:
NSString *s = [NSString stringWithCString:value encoding:NSASCIIStringEncoding];
Related
Hello All,
I have a problem regarding Unicode characters. I'm able to append Apple Art Work Unicode Characters in UITextView.
Like this : -
self.textView.text = #"\ue00A";
It is Okay.
But now i have many Unicodes Characters which're not in Apple art work.
One of them is U+1F3C7
Now I'm trying to show it in UITextView.
self.textView.text = #"\u1f3c7";
Then it is showing me an Special Character instead of Emoji.
This is the Emoji Icon of this Unicode But it is showing me Ἴ7.
Apple doesn't support all Unicode Characters ?
How can I add my own emojies in my application ?
Let me know if my question is not clear for you.
Doesn't Objective-C use UTF-16 internally, like Java and C#?
If so, then U+1F3C7 wouldn't be "\u1f3c7", but the surrogate-pair, "\uD83C\uDFC7".
Otherwise, there has to be some way to indicate a higher character, because "\u1f3c7" is the same as "\u1f3c" + "7", which is Ἴ7 (capital iota with psili and oxia, then 7).
Edit: After some discussion between the OP and myself, we figured out that the way to do this in Objective C is one I know as the C++ way:
"\U0001F3C7"
(\uXXXX with a small u and 4 hex digits works if it fits in thos 4 hex digits, \UXXXXXXXX with a capital U and 8 hex digits works for everything, but is longer to type).
Now our friend just needs to deal with the matter of font support, which alas is another problem in getting this to actually look as he wants.
I'd like to be able to simulate a terminal on my iPhone to play games like Nethack using the primitive graphics I enjoyed on a real DEC terminal. Nethack allows selection of DECgraphics for vt-compatible terminals or IBMGraphics for codepage 437 support.
I know that these special graphics characters are generated by strings sent to the terminal (vt100.net has a huge amount of information including the terminal manuals and test programs). I can receive and interpret those strings but I need to be able to reproduce and display those characters in a UIView.
It looks like kCFStringEncodingMacVT100 and kCFStringEncodingDOSLatinUS are the keys to the puzzle. Here's a bit of partial code showing what I tried to do to get "special characters" glyphs onto a UILabel:
UInt8 c = some value...
NSStringEncoding stringEncoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingMacVT100);
NSData *charData = [NSData dataWithBytes:&c length:1];
NSString *charString = [[NSString alloc] initWithData:charData encoding:stringEncoding];
label.font = [UIFont fontWithName:#"Courier New" size:20.f];
label.text = charString;
I tried values of c from 0 to 255. I can display characters from space to '~' with all the expected stuff in between using this code but there are no corners or other line characters at all. When there is no character to display, charString is nil.
Now I'm pretty sure the Courier New TTF has these characters - on my Mac I can play Nethack with the terminal font set to Courier New and I can set DECgraphics and the display is OK.
So the questions are:
what's wrong with the code above?
what freely available monospaced truetype fonts are there supporting the DEC special characters and/or codepage 437?
how can you test a TTF once you have it to be sure those glyphs are there?
how can you display these glyphs in a UILabel or similar?
(I don't want to use any of the graphical tilesets available, I don't like them. I know there are at least two Nethacks available for free already but none have the straightforward keyboard interface I want, I find the popup a window for everything approach really slow and frustrating. I know it's not an easy project. And I might want to to Angband one day.)
Most (all?) of the glyphs in CP437 have corresponding code points in the Unicode standard, as detailed on this Wikipedia article.
For example, to display a club, you can do the following. It works with the default UILabel font:
UniChar club = 0x2663;
NSString *clubString = [NSString stringWithCharacters:&club length:1];
[label setText:clubString];
Objective-C iOS Programming:
I need to display a number like 8.33333 just as 8.3, with the three having a macron (repeating number symbol, a bar line) above it. I have done some searching and have not found a solution to this. I have found the encoding for C/C++/Java source code being "\u0304" and for Unicode being "U+0304". Is there a way that I can create an NSString from a Unicode character? And how would a create a Unicode character with a macron?
Thanks.
For combining characters such as U+0304, the string should contain the original letter followed by the combining character. For instance,
NSString *str = #"ca\u0304t";
is a representation of cāt.
I am trying to read some text from a plist file and display it to the users in alert box.
When I build the string using this code, everything works (users sees Hello with a smily icon):
NSString *hello = #"Hello \ue415";
but when I get the string from plist, using this code, uses sees "Hello \ue415":
NString *hello = (NSString *)[pageLiteratureDic objectForKey:litratureKey];
Do I have to encode string differently? Any help or pointers will be much appreciated... everyone love emojis ;)
You shouldn't literally type "\ue415" as text into the plist file. \u.... is an escape sequence in the syntax of strings and characters in the C language. The string itself does not contain backslash and "u" and whatever, it contains just 1 character, the Unicode character at the codepoint 0xe415. If you want to save that in a plist, you have to manually type that one Unicode character in there yourself, making sure to use whatever encoding that is required of a plist (maybe utf-8 or utf-16, not sure). Alternately, you can write a program that creates a plist from that string, and then copy and paste whatever is in that plist file over to your file.
In the plist, instead of "Hello \ue415" try using the smily face character explicitly as in "Hello :)". Just cut and paste the smily character over the unicode code. The reading of the plist is probably escaping the backslash and stopping the interpretation as a unicode character.
How can i use Norwegian characters to show them in UILabel in my application.
if i use it directly it shows garbage value.
The characters should work. I'm using a UILabel which loads from a nib file into the view of a ViewController. The label works in Times New Roman and Palatino (and presumably other fonts) when I set the text with the following code: [myLabel setText:#"ÆØÅ æøå"]; . I would try copying and pasting that line directly and see what happens.
I would guess that you're getting your characters from somewhere whose representation is not quite right in NSString terms. I grabbed these from Wikipedia. (I don't speak Norwegian so I'm not sure if you need other non-English alphabet characters - as far as I could see these were the only ones.)