我有大约 640 行不同长度的文本行,它们既可以作为数据网格中的列表查看,也可以在单行 View 中查看。在单行 View 中,我想调整文本行的字体大小,以便它
完全适合文本字段
最大磅值 24 和最小磅值 10(我已在文本字段中为其设置了自定义属性)。
我在单行 View 卡片中使用了以下代码:
on resizeText
## Check if the text fits in the field
put the textSize of fld "foneline" into tTextSize
if the formattedHeight of fld "foneline" > the height of fld "foneline" then
## Make the text smaller until it fits
repeat until the formattedHeight of fld "foneline" <= the height of fld "foneline"
subtract 1 from tTextSize
## Check that the text size is not less that the minimum size
if tTextSize >= the cMinimumTextSize of fld "foneline" then
set the textSize of fld "foneline" to tTextSize
else
exit repeat
end if
end repeat
else if the formattedHeight of fld "foneline" < the height of fld "foneline" then
## Make the text as large as possible
repeat until the formattedHeight of fld "foneline" >= the height of fld "foneline"
add 1 to tTextSize
## Check that the text size is not bigger that the maximum size
if tTextSize<= the cMaximumTextSize of fld "foneline" then
set the textSize of fld "foneline" to tTextSize
else
exit repeat
end if
end repeat
end if
end resizeText
以及卡片上 Previous 和 Next 按钮代码中的 resizeText 命令。
然而,在显示的代码中存在一些小故障或错误,我希望您可以按照以下步骤进行复制:
打开堆栈
点击“全选”按钮
点击“线条”按钮
单击“下一步”按钮,直到您看到第 6 行(它的全长可见)。
再次单击“下一步”按钮,您将看到第 7 行,但该行并不完全可见(您会看到右引号 "不存在)
点击“Next”按钮,然后点击“Previous”按钮 - 这会将您带回到第 7 行,现在可以看到它的全长!
现在点击“上一步”按钮,第 6 行可见,但这次不是全长
点击“Previous”,然后再次点击“Next”,现在第 6 行已完整显示
点击“下一步”,第 7 行再次完全不可见。
如果您无法使用上面提到的行号复制它,请尝试继续单击“下一步”按钮,直到您遇到缺少结尾 "引号的行,这表明该行已被截断。然后按照与上面相同的步骤单击“上一个”和“下一个”按钮。这听起来可能很复杂,但是一旦你打开堆栈,就很容易找出错误的行为。类似的情况是行:83-84-85 ;48-49;51-52。 我的堆栈的链接是 DG-only-1.16_cut-off-lines.zip
如何更正代码,使其始终显示每一行而不切断行尾?
最佳答案
在您的“resizeText”处理程序中:如果格式化的高度小于该字段,那么您将调整文本的大小直到它>= formattedHeight。这意味着循环有时会在其高度大于所需高度时停止。通过在字体大小增加时添加最终高度检查,我们可以避免这种情况;
on resizeText
## Check if the text fits in the field
put the textSize of fld "foneline" into tTextSize
put the height of fld "foneline" into tHeight
if the formattedHeight of fld "foneline" > tHeight then
## Make the text smaller until it fits
repeat until the formattedHeight of fld "foneline" <= tHeight
subtract 1 from tTextSize
## Check that the text size is not less that the minimum size
if tTextSize >= the cMinimumTextSize of fld "foneline" then
set the textSize of fld "foneline" to tTextSize
else
exit repeat
end if
end repeat
else if the formattedHeight of fld "foneline" < tHeight then
## Make the text as large as possible
repeat until the formattedHeight of fld "foneline" >= tHeight
add 1 to tTextSize
## Check that the text size is not bigger that the maximum size
if tTextSize<= the cMaximumTextSize of fld "foneline" then
set the textSize of fld "foneline" to tTextSize
else
exit repeat
end if
end repeat
# check the final field height
if the formattedHeight of fld "foneline" > tHeight then
subtract 1 from tTextSize
set the textSize of fld "foneline" to tTextSize
end if
end if
end resizeText
关于textfield - 动态文本大小调整以适应整个文本行到文本字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24794763/