How does one use the CGRectIntegral function? I understand it's purpose.
The documentation isn't clear on it's exact use.
CGRectIntegral to convert any decimal values to their integer equivalents
see image may be you can understand
How do I fix it?
frame = CGRectIntegral(frame);
-OR-
myTextView.frame = CGRectIntegral(myTextView.frame);
see this for more information of CGRectIntegral
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. */
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With