Home > DeveloperSection > Forums > How to print CGRect value using NSLog?
Monaj Singh
Monaj Singh

Total Post:41

Posted on    January-18-2016 7:24 AM

 iPhone iPhone  Ios  Objective C 

 1 Reply(s)
 603  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.

Tarun Kumar

Total Post:214

Posted on    January-18-2016 7:38 AM

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

Don't want to miss updates? Please click the below button!

Follow MindStick