我正在尝试设置字体颜色,但由于某种原因它无法正常工作
public void ConvertToLinkButton(UIButton btn, String hyperlink)
{
CTStringAttributes attributesHyperLink = new CTStringAttributes();
attributesHyperLink.UnderlineStyle = CTUnderlineStyle.Single;
attributesHyperLink.ForegroundColor = UIColor.Purple.CGColor;
NSMutableAttributedString attrString = new NSMutableAttributedString(btn.TitleLabel.Text);
attrString.AddAttributes(attributesHyperLink, new NSRange(btn.TitleLabel.Text.IndexOf(hyperlink), hyperlink.Length));
btn.TitleLabel.AttributedText = attrString;
}
这让我想知道为什么会这样?
答案 0 :(得分:2)
你应该尝试使用UIKit的UIStringAttributes而不是CoreText的CTStringAttributes。
UIStringAttributes attributesHyperLink = new UIStringAttributes();
attributesHyperLink.UnderlineStyle = NSUnderlineStyle.Single;
attributesHyperLink.ForegroundColor = UIColor.Purple.CGColor;