Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin 属性字符串字体颜色不工作_Xamarin_Xamarin.ios_Nsattributedstring_Nsmutableattributedstring_Nsattributedescription - Fatal编程技术网

Xamarin 属性字符串字体颜色不工作

Xamarin 属性字符串字体颜色不工作,xamarin,xamarin.ios,nsattributedstring,nsmutableattributedstring,nsattributedescription,Xamarin,Xamarin.ios,Nsattributedstring,Nsmutableattributedstring,Nsattributedescription,我正在尝试设置字体颜色,但由于某些原因它无法工作 公共无效转换链接按钮(UIButton btn,字符串超链接) { ctStringAttributesHyperlink=新的CTStringAttributes(); attributesHyperLink.UnderlineStyle=cUnderlineStyle.Single; attributesHyperLink.ForegroundColor=UIColor.Purple.CGColor; NSMutableAttributedS

我正在尝试设置字体颜色,但由于某些原因它无法工作

公共无效转换链接按钮(UIButton btn,字符串超链接)
{
ctStringAttributesHyperlink=新的CTStringAttributes();
attributesHyperLink.UnderlineStyle=cUnderlineStyle.Single;
attributesHyperLink.ForegroundColor=UIColor.Purple.CGColor;
NSMutableAttributedString attrString=新的NSMutableAttributedString(btn.TitleLabel.Text);
attrString.AddAttributes(attributesHyperLink,新的NSRange(btn.TitleLabel.Text.IndexOf(hyperlink),hyperlink.Length));
btn.TitleLabel.AttributeText=attrString;
}
这让我想知道为什么会发生这种情况?

你应该试试UIKit而不是CoreText的CTStringAttributes

UIStringAttributes attributesHyperLink=新的UIStringAttributes();
attributesHyperLink.UnderlineStyle=NSUnderlineStyle.Single;
attributesHyperLink.ForegroundColor=UIColor.Purple.CGColor;

@DuraiAmuthan.H老实说,我不确定。但是,CoreText是一种低级技术,更适合于需要低级文本处理功能的情况。UIKit的UIStringAttributes在这里提供了您所需要的一切,这就是我以前使用过的。