2017-09-17 26 views
0

AttributedText我的UILabel的無屬性Monotouch。 UIlabel.AttributedText。屬性不起作用

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; 

我究竟做錯了渲染?

感謝:)

回答

0

如下修改代碼:

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; 

Style Text

+0

非常感謝!有用 : ) –