How to print CGRect value using NSLog?

Total Post:41

 970  View(s)
Rate this:

I want to know how can I print CGRect attributes(frame) values on console using NSLog() method.
I tried to see properties of CGRect, like this:

NSLog(@"CGRect Value: %@", rect);

But, I got error which will says CGRect is not an id type. So, how can I print the frame of CGRect for getting attributes.

  1. Post:214

    Re: How to print CGRect value using NSLog?

    Yes, we can't print CGRect attributes directly in NSLog.
    for that, cocoa provides us a method NSStringFromCGRect, because it will convert the CG structs into nsstring- below we are provided an example:

    NSLog(@"CGRect Value: %@", NSStringFromCGRect(rect));

    I'm providing some other functions which can help you to print CG struct values:
    1. NSStringFromCGRect
    2. NSStringFromCGSize
    3. NSStringFromCGPoint
    4. NSStringFromUIEdgeInsets
    5. NSStringFromCGAffineTransform