单点触控。UIlabel.AttributedText. 属性不起作用



我的uilabel的属性文本没有属性

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;

我在做什么错?

谢谢:)

修改您的代码如下:

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;

请参阅样式文本

最新更新