HOW TO PRINT CGRECT VALUE USING NSLOG?

Monaj Singh

Total Post:41

Points:287
Posted by  Monaj Singh
 618  View(s)
Ratings:
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. Tarun Kumar

    Post:214

    Points:1642
    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!