以 Unicode 字符为标题的 Xamarin.iOS UIBarButtonItem [英] Xamarin.iOS UIBarButtonItem With Unicode Character as Title

查看:32
本文介绍了以 Unicode 字符为标题的 Xamarin.iOS UIBarButtonItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于 Xamarin.iOS 项目,我尝试将 Unicode 字符(齿轮图标)用于顶部菜单中的左栏按钮项.我可以为此使用自定义图标,我在此处阅读了一些 iOS 帖子,以便您也可以使用 Unicode 字符.所以我按照一个例子,从 Swift 翻译而来,一切都很好,除了我的按钮标题总是文字 Unicode 字符串而不是解码的齿轮图标.

With a Xamarin.iOS project, I'm trying to use a Unicode character (gear icon) for the left bar button item in my top menu. I could use a custom icon for this, bit I read on some iOS posts here on SO that you can also use Unicode characters. So I followed an example, translated form Swift and it all works fine, except that my button title is always the literal Unicode string instead of the decoded gear icon.

此外,下面的代码将无法构建,因为该字符串 ("\u{2699}") 需要转义.我使用了 \ 和 @ 转义方法,但我总是在我的按钮中得到文字字符串.知道我做错了什么吗?

Also, the code below will not build because that string ("\u{2699}") needs to be escaped. I've used \ and @ escaping methods but I always end up with just the literal string in my button. Any ideas what I'm doing wrong?

var ltButton = new UIBarButtonItem();
ltButton.Title = new NSString("\u{2699}", NSStringEncoding.UTF8);
ltButton.Style = UIBarButtonItemStyle.Plain;

var font = UIFont.FromName("Helvetica", 18.0f);
ltButton.SetTitleTextAttributes(new UITextAttributes { Font = font }, UIControlState.Normal);

this.NavigationItem.SetLeftBarButtonItem(ltButton, true);

推荐答案

这就是你所需要的:

ltButton.Title = "\u2699";

ltButton.Title = "\uD83D\uDE03";

这篇关于以 Unicode 字符为标题的 Xamarin.iOS UIBarButtonItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆