How to display the copyright icon in UILabel text?
-
06-07-2019 - |
Question
Does any one know how to display the copyright icon in UILabel text? This is the icon with a circle around c. The html code for it is: ©
or ©
.
I tried the following code:
UILabel *contactInfo = [[UILabel alloc] initWithFrame:CGRectMake(-55,135,420,100)];
contactInfo.text = @"'©):'2009 Nationwide ";
or
contactInfo.text = @"'©'2009 Nationwide ";
or
contactInfo.text = @"©2009 Nationwide ";
It just prints everything as text and no icon.
This would work in a webView but I need it as UILabel text. Any help?
Solution
If your source files are in UTF-8, what they should be, this should work just fine. Otherwise you should use .strings-files in combination with the NSLocalizedString() macro and put your text into UTF-16 files.
Works for me: myUILabel.text = @"© by me";
(source: hillrippers.ch)
Edit: Now that I see that you've tried to insert the symbol as HTML entity - this does not work, just insert the symbol as it appears.
OTHER TIPS
In interface builder try Option and G together.
If you don't have an Option key, try with ALT.
Another way to insert symbols without dealing with your source files' character encoding is to encode them as UTF-8 bytes using \x
escapes.
According to Fileformat.info, the Copyright sign in UTF-8 bytes is 0xC2 0xA9.
So this works: @"\xC2\xA9 Nationwide"
That's how I do all of mine.
Copy and paste the copyright symbol © directly into your source code.
It's usually not a great idea to put non-ASCII strings through the compiler. The UTF-8 approach is thus better, if unreadable. You could use
NSLocalizedString(@"copyright", @"");
and then a .strings file with
copyright = "©2009";
would be a lot easier to generalize to other non-ASCII strings.
(BTW, it's option + g, not option + c.)
From iOS6> we can use NSAttributedString concept. Please see the below code snippet. Please ignore if anyone already aware of this.
static NSString *html =
@"<html>"
" <body>Here is copyright © </i></body>"
"</html>";
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 280, 300, 200)];
NSError *err = nil;
label.attributedText =
[[NSAttributedString alloc]
initWithData: [html dataUsingEncoding:NSUTF8StringEncoding]
options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType }
documentAttributes: nil
error: &err];
if(err)
NSLog(@"Unable to parse label text: %@", err);