Ios 带有CTStringAttributes和NSMutableAttributeString的CTFont使我在xamarin中的应用程序崩溃

Ios 带有CTStringAttributes和NSMutableAttributeString的CTFont使我在xamarin中的应用程序崩溃,ios,xamarin.ios,xamarin,nsattributedstring,ctfont,Ios,Xamarin.ios,Xamarin,Nsattributedstring,Ctfont,我正在尝试创建nsmutableAttributeString,并使用SetProperties方法设置其属性。但是我的应用程序出错了 MonoTouch.Foundation.MonoTouchException exception - NSInvalidArgumentException Reason: unrecognized selector sent to instance 0xc305d00.* 代码: 此代码位于UITableViewController的GetCell方法中。我

我正在尝试创建
nsmutableAttributeString
,并使用
SetProperties
方法设置其属性。但是我的应用程序出错了

MonoTouch.Foundation.MonoTouchException exception - NSInvalidArgumentException Reason: unrecognized selector sent to instance 0xc305d00.*
代码:

此代码位于
UITableViewController
GetCell
方法中。我想能够改变字体或颜色,只有前3-4个字母的字符串

我发现,如果我消除字体组件并设置另一个属性,例如StrokeWidth,它可以正常工作

var attrs = new CTStringAttributes { /*Font = font*/ StrokeWidth = 5f };
所以看起来字体初始化有点不正确。为什么呢?为什么它会使我的应用程序崩溃


谢谢你的进步

以下是一个使用
UIStringAttributes
的示例:

        string line1 = "Don't have Facebook?", line2 = "\nCreate or sign in with an alternate account";
        var attributedString = new NSMutableAttributedString(line1 + line2);

        attributedString.SetAttributes(new UIStringAttributes
        {
            Font = Theme.BoldSmallFont,
            ForegroundColor = Theme.LightGray,

        }.Dictionary, new NSRange(0, line1.Length));

        attributedString.SetAttributes(new UIStringAttributes
        {
            Font = Theme.RegularSmallFont,
            ForegroundColor = Theme.LightGray,

        }.Dictionary, new NSRange(line1.Length, line2.Length));

        _alternateSignIn.SetAttributedTitle(attributedString, UIControlState.Normal);
这是在
ui按钮上设置两种不同字体的示例<代码>主题
是我自己的静态类,你可以用自己的颜色和字体替换

使用
UIStringAttributes
应该能够完成与使用
CTStringAttributes
相同的任务。您可能会向Xamarin发布崩溃案例的错误报告:


*注意:属性字符串仅适用于iOS 6及更高版本。这就是苹果添加这些API的时候。

我也遇到了同样的问题,我想是使用了
UIStringAttribute
。当我开始工作时,让我给你发一个代码示例。我试图在一个简单的程序中重新编写这个bug,但我得到了预期的输出(字体和所有)。请提供完整的复印件。太好了!工作完美。非常感谢你。
        string line1 = "Don't have Facebook?", line2 = "\nCreate or sign in with an alternate account";
        var attributedString = new NSMutableAttributedString(line1 + line2);

        attributedString.SetAttributes(new UIStringAttributes
        {
            Font = Theme.BoldSmallFont,
            ForegroundColor = Theme.LightGray,

        }.Dictionary, new NSRange(0, line1.Length));

        attributedString.SetAttributes(new UIStringAttributes
        {
            Font = Theme.RegularSmallFont,
            ForegroundColor = Theme.LightGray,

        }.Dictionary, new NSRange(line1.Length, line2.Length));

        _alternateSignIn.SetAttributedTitle(attributedString, UIControlState.Normal);