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在这里提供了您所需要的一切,这就是我以前使用过的。