如何在UILabel文本中显示版权图标?

发布于 2024-08-08 13:20:40 字数 552 浏览 4 评论 0原文

有谁知道如何在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

罪#恶を代价 2024-08-15 13:20:40

在界面生成器中尝试将 OptionG 一起使用。

如果您没有 Option 键,请尝试使用 ALT

In interface builder try Option and G together.

If you don't have an Option key, try with ALT.

第七度阳光i 2024-08-15 13:20:40

如果您的源文件采用 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";

© 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.

唠甜嗑 2024-08-15 13:20:40

另一种插入符号而不处理源文件字符编码的方法是使用 \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.

黑白记忆 2024-08-15 13:20:40

将版权符号 © 直接复制并粘贴到源代码中。

Copy and paste the copyright symbol © directly into your source code.

晚风撩人 2024-08-15 13:20:40

将非 ASCII 字符串放入编译器通常不是一个好主意。因此,UTF-8 方法虽然不可读,但更好。您可以使用

NSLocalizedString(@"copyright", @"");

.strings 文件,这样

copyright = "©2009";

可以更容易地推广到其他非 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

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.)

拍不死你 2024-08-15 13:20:40

从iOS6开始>我们可以使用 NSAttributedString 概念。请参阅下面的代码片段。如果有人已经意识到这一点,请忽略。

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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文