且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

快速如何让 UILabel 对齐到左上角

更新时间:2023-10-03 21:51:46

我想知道是否可以从标签左上角的第一个单词开始

I'm trying to find out if I can start the first word at the top left of the label

不,你不能.这不是标签在文本更改时绘制的方式.

No, you can’t. That’s not how labels draw when their text changes.

很酷的解决方法:从包含整个文本的标签开始,但使用属性字符串,以便文本与背景颜色相同(例如,白底白字)从而不可见.在您的计时器中,一次将一个单词的颜色更改为黑色.

Cool workaround: start with the label containing the whole text, but use an attributed string so that the text is the same color as the background (e.g. white on white) and thus invisible. In your timer, change the color of one word at a time to black.

这样,您永远不会更改文本,只会更改颜色,因此文本不会随着每个单词的显示而移动.

That way, you never change the text, just the color, so the text does not move as each word is revealed.