如何在UILabel文本中显示版权图标?
有谁知道如何在 UILabel 文本中显示版权图标?这是 c 周围有一个圆圈的图标。它的 html 代码是:©
或 ©
。
我尝试了以下代码:
UILabel *contactInfo = [[UILabel alloc] initWithFrame:CGRectMake(-55,135,420,100)];
contactInfo.text = @"'©):'2009 Nationwide ";
or
contactInfo.text = @"'©'2009 Nationwide ";
or
contactInfo.text = @"©2009 Nationwide ";
它只是将所有内容打印为文本,没有图标。
这可以在 webView 中工作,但我需要它作为 UILabel 文本。 有什么帮助吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
在界面生成器中尝试将 Option 和 G 一起使用。
如果您没有 Option 键,请尝试使用 ALT。
In interface builder try Option and G together.
If you don't have an Option key, try with ALT.
如果您的源文件采用 UTF-8 格式(它们应该是这样),那么这应该可以正常工作。否则,您应该将 .strings-files 与 NSLocalizedString() 宏结合使用,并将文本放入 UTF-16 文件中。
对我有用:
myUILabel.text = @"© by me";
(来源:hillrippers。 ch)
编辑:
现在我发现您已尝试将符号作为 HTML 实体插入 - 这不起作用,只需按显示的方式插入符号即可。
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.
另一种插入符号而不处理源文件字符编码的方法是使用
\x
转义符将它们编码为 UTF-8 字节。根据Fileformat.info,版权符号采用UTF-8字节为 0xC2 0xA9。
所以这是可行的:
@"\xC2\xA9 Nationwide"
这就是我所做的一切。
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.
将非 ASCII 字符串放入编译器通常不是一个好主意。因此,UTF-8 方法虽然不可读,但更好。您可以使用
.strings 文件,这样
可以更容易地推广到其他非 ASCII 字符串。
(顺便说一句,是选项+g,而不是选项+c。)
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
and then a .strings file with
would be a lot easier to generalize to other non-ASCII strings.
(BTW, it's option + g, not option + c.)
从iOS6开始>我们可以使用 NSAttributedString 概念。请参阅下面的代码片段。如果有人已经意识到这一点,请忽略。
From iOS6> we can use NSAttributedString concept. Please see the below code snippet. Please ignore if anyone already aware of this.