2

Je suis en train de définir la couleur de la police et sa ne fonctionne pas pour une raison quelconquefont color chaîne Attribuée ne fonctionne pas

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

Je me demande pourquoi est-il passe?

Répondre

2

Vous devriez essayer le code UIStringAttributes d'UIKit au lieu de CTStringAttributes de CoreText.

UIStringAttributes attributesHyperLink = new UIStringAttributes(); 
attributesHyperLink.UnderlineStyle = NSUnderlineStyle.Single; 
attributesHyperLink.ForegroundColor = UIColor.Purple.CGColor; 
+0

Merci, mais pourquoi cela ne fonctionne-t-il pas? –

+1

@ DuraiAmuthan.H Honnêtement, je ne suis pas sûr. Cependant, CoreText est une technologie de bas niveau qui convient mieux aux cas où vous avez vraiment besoin de fonctionnalités de traitement de texte de bas niveau. UIStringAttributes de UIKit fournit tout ce dont vous avez besoin ici et c'est ce que j'ai utilisé auparavant. – hankide