代码之家  ›  专栏  ›  技术社区  ›  Egor Kazachenko

单触。UIlabel。AttributeText。属性不起作用

  •  0
  • Egor Kazachenko  · 技术社区  · 9 年前

    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;
    

    谢谢:)

    1 回复  |  直到 9 年前
        1
  •  0
  •   ColeX    9 年前

    修改代码如下:

    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