UILabel not wrapping text correctly sometimes (auto layout)

前端 未结 3 789
北荒
北荒 2020-12-13 03:56

I have a uilabel setup in a view. It doesn\'t have a width constraint, but its width is instead determined by a leading constraint to the thumbnail image, and a trailing con

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-13 04:24

    Also, check that you are passing integral numbers to your layout constraints in code.

    For me it happened that after some calculations (e.g. convertPoint:toView:), I was passing in something like 23.99999997, and eventually this lead to a 2-line label displaying as a one-liner (although its frame seemed to be calculated correctly). In my case CGRectIntegral did the trick!

    Rounding errors could kill ya :)

提交回复
热议问题