UITableViewCell渲染错误

huangapple go评论49阅读模式
英文:

UITableViewCell renders wrongly

问题

My UITableViewCell lines are not working properly. If the label has a long text the wrapping of the text is not made as planned and the cell constraints are also not laying out the cell as should. Line randomly look like these:

UITableViewCell渲染错误

First 3 lines are ok, next two is laid out bad. text should wrap inside.

What is causing this?

The label is constraint on the front and end. The end is constraint to the switch with a larger or equal to 10. Switch is constraint to the right edge. Left and Right constraints are with priority 1000, label to switch with 750.

英文:

My UITableViewCell lines are not working properly. If the label has a long text the wrapping of the text is not made as planned and the cell constraints are also not laying out the cell as should. Line randomly look like these:

UITableViewCell渲染错误

First 3 lines are ok, next two is laid out bad. text should wrap inside.

What is causing this?

The label is constraint on the front and end. The end is constraint to the switch with a larger or equal to 10. Switch is constraint to the right edge. Left and Right constraints are with priority 1000, label to switch with 750.

答案1

得分: 1

你不应该需要更改任何优先级,并且不需要设置开关的宽度...

这是单元格的原型 --

  • 标签(黄色背景以便我们看到它的框架)
    • 顶部/前导/底部约束到内容视图边距
    • 行数:0
  • 开关
    • 顶部/尾部约束到内容视图边距
    • 前导约束到标签尾部 >= 10

在Storyboard中看起来像这样:

UITableViewCell渲染错误

在运行时看起来像这样:

UITableViewCell渲染错误

所有约束的优先级都保持默认值。

英文:

You shouldn't need to change any priorities, and you do not need to set the width of the switch...

Here is the cell prototype --

  • label (yellow background so we can see its frame)
    • constrained Top / Leading / Bottom to content view margins
    • number of lines: 0
  • switch
    • constrained Top / Trailing to content view margins
    • Leading to label Trailing >= 10

Looks like this in Storyboard:

UITableViewCell渲染错误

and looks like this when running:

UITableViewCell渲染错误

All constraint priorities are at their defaults.

huangapple
  • 本文由 发表于 2023年6月1日 02:39:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76376428.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定