2017-09-17 4 views
0

AttributedText de mon UILabel rendu sans attributsMonotouch. UIlabel.AttributedText. Les attributs ne fonctionne pas

var labelText = new NSMutableAttributedString(cell.MessageLabel.Text, underlineStyle: NSUnderlineStyle.ByWord); 
     foreach (ErrorJson error in messages[indexPath.Section].ErrorsData[indexPath.Row].errorsData.errors) 
     { 
      labelText.AddAttribute(CTStringAttributeKey.ForegroundColor, UIColor.FromRGB(255, 230, 58), new NSRange(error.offset, error.length)); 
      labelText.AddAttribute(CTStringAttributeKey.UnderlineColor, UIColor.FromRGB(255, 230, 58), new NSRange(error.offset, error.length)); 
     } 
     cell.MessageLabel.AttributedText = labelText; 

ce que je fais mal?

Merci:)

Répondre

0

Modifier votre code comme ci-dessous:

var labelText = new NSMutableAttributedString(cell.MessageLabel.Text, underlineStyle: NSUnderlineStyle.Single); 

var Attributes = new UIStringAttributes 
{ 
    ForegroundColor = UIColor.FromRGB(255, 230, 58), 
    UnderlineColor = UIColor.FromRGB(255, 230, 58), 
}; 

foreach (ErrorJson error in messages[indexPath.Section].ErrorsData[indexPath.Row].errorsData.errors) 
{ 
    labelText.AddAttributes(Attributes.Dictionary, new NSRange(error.offset, error.length)); 
} 
cell.MessageLabel.AttributedText = labelText; 

se réfèrent à Style Text

+0

merci beaucoup! Ça marche :) –