【问题标题】:Monotouch. UIlabel.AttributedText. Attributes doesn't work单触。 UIlabel.AttributedText。属性不起作用
【发布时间】:2017-09-17 18:32:18
【问题描述】:

我的 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;

我做错了什么?

谢谢:)

【问题讨论】:

    标签: xamarin.ios uilabel nsattributedstring


    【解决方案1】:

    修改你的代码如下:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-15
      • 2021-06-21
      • 2016-02-12
      • 1970-01-01
      • 2016-02-06
      • 2011-03-31
      • 2018-11-19
      • 2012-07-23
      相关资源
      最近更新 更多