Cocoprogrmr
Cocoprogrmr

Reputation: 31

Objective-C: Height of CGRect?

I want to get the height of a CGRect-rectangle. I have a simple problem in understanding why these lines return 0 height:

    CGRect lalaframe = CGRectMake(10, 30, 45, 50);
    NSLog(@"_height of test frame = %d",lalaframe.size.height);

Should be an easy fix... Thanks!

Upvotes: 0

Views: 363

Answers (3)

Robybyte
Robybyte

Reputation: 99

use:

NSLog("_height of test frame: %f", lalaframe.size.height);

It will log the height of the frame.

%d is for decimal numbers (int, long, short) %f is for floating numbers (float, double)

Upvotes: 0

VdesmedT
VdesmedT

Reputation: 9113

agree with cobbal. I use

NSLog(@"frame :%@", NSStringFromCGRect(lalaframe))

most of the time because of its simplicity.

Upvotes: 1

cobbal
cobbal

Reputation: 70733

You're logging with %d, that formats an integer. Try using %f (for float) instead.

Upvotes: 7

Related Questions