作者:mobiledu2402851173 | 来源:互联网 | 2023-05-16 02:19
InaUITableViewthatneedstodisplayalonglistofchatlikeconversations,oftencontainingemoji
In a UITableView
that needs to display a long list of chatlike conversations, often containing emojis, a size calculation error occurs.
在UITableView中,需要显示一长串聊天式的对话列表(通常包含表情符号),会出现大小计算错误。
My problem is, that if a string is just the right length, and I use sizeWithFont
, I on my first measurement using sizewithfont
get an incorrect length of the string, causing a "linebreak".
我的问题是,如果一个字符串刚好是正确的长度,并且我使用sizeWithFont,我在第一次使用sizeWithFont的测量中得到了一个不正确的字符串长度,导致了一个“换行符”。
I assume that it is because the string ":-)" is broader than the actual smiley icon.
我认为这是因为字符串“:-)”比真正的笑脸图标要宽。
The evidence can be seen here :
证据可以在这里看到:
![Using <code>SizeWithFont</code>](https://www.#.com/go/aHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9zZ2d3Mi5wbmc=)
Now, over at some other stacks, some claim that sizeWithFont
will only account for the string, not the Emoji, which for me doesn't make sense, since it gets it right "eventually"...
现在,在其他的一些堆叠中,有人声称sizeWithFont只代表字符串,而不是表情符号,这对我来说毫无意义,因为它“最终”做到了……
But they propose using sizeToFit instead, so I decided to give it a go.
但他们建议改用sizeToFit,所以我决定试试。
![Using SizeToFit](https://www.#.com/go/aHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9zT25Dai5wbmc=)
Bam, same result.
Bam,相同的结果。
Does anyone know how to counter this ? Is there a boolean
to check if "Label is done being emoji-processed" so i can skip that call ?
有人知道如何应对吗?是否有一个布尔值来检查是否“标签已经完成表情包处理”以便我可以跳过这个调用?
Running the same line twice does nothing, it seems the view needs to be drawn, before sizeWithFont
realises its mistake.
在sizeWithFont意识到它的错误之前,两次运行同一条线没有任何作用,看起来视图需要被绘制。
The shown column is run in a - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
segment, on a custom cell. I can replicate the error on a perfectly regular UITableViewCell as well, so that doesn't seem to be it.
显示的列在自定义单元格上的- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath段中运行。我也可以在一个完全正常的UITableViewCell上复制错误,所以看起来不是这样的。
2 个解决方案