CGRectIntegral what is the usage of it?

前端 未结 3 1078
小蘑菇
小蘑菇 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:01

    CGRectIntegral to convert any decimal values to their integer equivalents
    see image may be you can understand enter image description here

    How do I fix it?

    frame = CGRectIntegral(frame);
    

    -OR-

    myTextView.frame = CGRectIntegral(myTextView.frame);
    

      see this for more information of CGRectIntegral

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-08 05:26

    CGRectIntegral Method is used to create integer rect . I mean to say suppose if you calculate frame in app you may get frames value in float.

    Setting float value as frame to some UIElement like UILabel would make the text looks blur. To avoid that, we use CGRectIntegral.Please look at the example below,

    NSLog(@"%@",NSStringFromCGRect(   CGRectIntegral(CGRectMake(0, 15.6, 16.1, 20.2))));
    

    This will print, {0,15},{17,21}.

    This explanation is found in the header file.

    /* Expand `rect' to the smallest rect containing it with integral origin and
       size. */
    
    0 讨论(0)
提交回复
热议问题