[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to know the geometry of a string on the screen ?

From: Bertrand Gmail
Subject: How to know the geometry of a string on the screen ?
Date: Fri, 27 Oct 2017 19:49:08 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1

Hello everyone.

I want to know the length of the string @"GNUstep" on the screen with sizeWithAttributes and the following code doesn't work :

NSFont *menuFont=[NSFont menuFontOfSize:0];
NSMutableDictionary *attributes ;
attributes = [NSMutableDictionary new];
[attributes setObject :menuFont
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString: @"GNUstep" ];
[string setAttributes:attributes range:NSMakeRange(0,[string length])];
NSSize stringSize;
stringSize=[[NSString string] sizeWithAttributes:attributes];
 printf("stringSize.width : %f \n", stringSize.width);
 /*Debug end*/

stringSize.width returns 1 for now. Why ?

Could somone please help me ?

Cheers, Bertrand Dekoninck

reply via email to

[Prev in Thread] Current Thread [Next in Thread]