Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGRectIntegral what is the usage of it?

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

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

like image 722
aksani56 Avatar asked Apr 02 '12 11:04

aksani56


3 Answers

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

like image 73
Hector Avatar answered Nov 09 '22 19:11

Hector


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. */
like image 26
Vignesh Avatar answered Nov 09 '22 18:11

Vignesh


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.

like image 8
Mike Weller Avatar answered Nov 09 '22 19:11

Mike Weller