2

我正在尝试设置字体颜色,但由于某种原因它不起作用

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;
}

这让我想知道为什么会这样?

4

1 回答 1

2

您应该尝试 UIKit 的UIStringAttributes而不是 CoreText 的 CTStringAttributes。

UIStringAttributes attributesHyperLink = new UIStringAttributes();
attributesHyperLink.UnderlineStyle = NSUnderlineStyle.Single;
attributesHyperLink.ForegroundColor = UIColor.Purple.CGColor;
于 2017-03-16T21:10:30.250 回答