【问题标题】:How to set the text style property of a field content in LiveCode如何在 LiveCode 中设置字段内容的文本样式属性
【发布时间】:2014-07-11 14:13:19
【问题描述】:

我的 LiveCode 应用中有一个滚动字段,如下所示:

答:约翰·罗杰斯 234 9th
B: 亨利福特 555 1st
C:简方达 224 5th

我想让每行中的最后一个词(即第 9、第 1、第 5 个位置)具有特定的文本样式。例如,将其设为红色。

我尝试了几件事,包括使用此代码迭代行:

repeat for each line lC in  field "fcontent"  
  set the foregroundColor of lC to "red"  
end repeat

...但不断收到错误消息。请有人让我走上正轨?

【问题讨论】:

    标签: text properties field livecode


    【解决方案1】:

    您使用 foreGroundColor 的解决方案几乎是正确的。您需要改用 textColor,并且在这种情况下,您不能对每个控制结构使用重复。

    repeat with x = 1 to the number of lines of fld "fcontent"
      set the textColor of the last word of line x of fld "fcontent" to red
    end repeat
    

    Red 不需要引号,因为它在 LiveCode 中定义为常量。

    【讨论】:

    • 但是为什么'repeat for each'结构在这里不起作用?
    • repeat-foreach 循环中的 LC 变量是字符串,而不是块引用。块引用的形式是“卡片 c 的字段 z 的行 x 到 y”,而字符串实际上只是字符串(“9th”、“1st”和“5th”)。因此,您可以设置块引用的 textColor 但不能设置字符串。
    • 我刚刚注意到...不是你的,而是 dtechplus 的。
    • 美丽。谢谢马克。
    【解决方案2】:

    标记解决方案是正确的。查看您的问题,您提到要设置每行最后一个单词的颜色。您可以将“最后一句话”添加到 Mark 的脚本中,您应该会得到您正在寻找的内容:

    repeat with x = 1 to the number of lines of fld "fcontent"
       set the textColor of the last word of line x of fld "fcontent" to "255,0,100"
    end repeat
    

    【讨论】:

    • 是的。谢啦。在发布我的代码时,我以某种方式省略了“最后一句话”。但我现在知道我的主要错误是没有意识到我必须使用 textColor 而不是foregroundColor!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-29
    • 1970-01-01
    • 2018-04-08
    • 1970-01-01
    • 1970-01-01
    • 2018-06-13
    相关资源
    最近更新 更多