CGRectIntegral what is the usage of it?

前端 未结 3 1085
小蘑菇
小蘑菇 2020-12-08 04:20

How does one use the CGRectIntegral function? I understand it\'s purpose.

The documentation isn\'t clear on it\'s exact use.

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-08 05:17

    One particular usage is to fix frames that do not align perfectly with on-screen pixels.

    See this question: UITextField blurred text

    If a label or textfield has a frame that isn't pixel-aligned when rendered to the screen, the text will appear blurred. This can happen if you calculate the frame using division (for example to center it in a parent view).

    CGRectIntegral will remove the fractional part of the frame, fixing this problem. Note however that with retina displays a .5 frame value is pixel aligned, but CGRectIntgral will still remove the fractional part.

提交回复
热议问题