2017-09-17 1 views
0

AttributedText meiner UILabel ohne Attribute gerendertMonotouch. UIlabel.AttributedText. Attribute funktioniert nicht

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; 

, was mache ich falsch?

Danke:)

Antwort

0

Code wie unten ändern:

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; 

siehe Style Text

+0

vielen Dank! Es klappt :) –