【问题标题】:Re-size the Text and Button/Label in Livecode在 Livecode 中重新调整文本和按钮/标签的大小
【发布时间】:2014-12-30 01:32:00
【问题描述】:

我有一个带有按钮和标签的 livecode 项目。当我重新调整窗口(堆栈)的大小时,我希望按钮和标签的宽度和高度发生变化。另外,我希望更改标签和按钮中文本的字体大小。我想随着字体大小的变化使文本的水平和垂直对齐居中。我尝试了这段代码,但文本超过了按钮/标签的高度(在更大的窗口大小中)。

set the width of field "label" to the width of this stack * 0.8
set the height of field "label" to the height of this stack * 0.2
set the textsize of field "label" to the height of field "label" - 10
set the textheight of field "label" to the height of field "label"

这正是我所期待的......

我怎样才能做到这一点?

【问题讨论】:

    标签: height width livecode text-size


    【解决方案1】:

    在调整堆栈窗口大小时平滑调整文本大小的问题是一个棘手的问题。这是一个可能不完美的解决方案,但它可以让您接近。该字段将 dontWrap 设置为 true,边距设置为 2。我还为该字段设置了初始 textFont 和 textSize,因此它不仅仅是使用继承的 textFont。

    此处理程序位于字段所在卡片的脚本中。

    on resizeStack pNewWidth, pNewHeight
        set the width of field "label" to pNewWidth * 0.8
        set the height of field "label" to pNewHeight * 0.2
        set the topLeft of fld "label" to pNewWidth * 0.1, pNewHeight * 0.1
        lock screen
        if the formattedWidth of fld "label" > the width of fld "label" OR \
              the formattedHeight of fld "label" > the height of fld "label" then
            set the textSize of field "label" to the textSize of fld "label" - 1
        else if the formattedWidth of fld "label" < the width of fld "label" OR \
              the formattedHeight of fld "label" < the height of fld "label" then
            set the textSize of field "label" to the textSize of fld "label" + 1
        end if
        unlock screen
    end resizeStack
    

    【讨论】:

    • 当我重新调整有时烦人的窗口大小时,文本似乎在振动。
    • 是的,这就是我说这种方法“不完美”时的意思。您可以探索 measureText() 函数以及堆栈的 scaleFactor 属性以获得更多想法。
    • 我找到了这个脚本` measureText(, , [ ])`这个怎么用?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-27
    • 2014-02-16
    • 1970-01-01
    • 1970-01-01
    • 2012-03-20
    相关资源
    最近更新 更多