我有一个带有按钮和标签的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"
这就是我期待的......
我怎样才能做到这一点?
答案 0 :(得分:0)
在调整堆栈窗口大小时平滑调整文本大小的问题是一个棘手的问题。这是一个可能不完美的解决方案,但它会让你接近。该字段的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