简体   繁体   中英

How to get the width and height of a string knowing its font size in iPhone?

I want to know if there is any way to determine the width and height of a string depending on the font name and font size used?

Thanks in advance!

Have a look at the sizeWithFont: method. That should be helpful. Depending on what your exact needs are, you can choose any one of the sister methods too.

You can use

– sizeWithFont:  
– sizeWithFont:forWidth:lineBreakMode:  
– sizeWithFont:constrainedToSize:  
– sizeWithFont:constrainedToSize:lineBreakMode:  
– sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:

Take a look at here

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/NSString_UIKit_Additions/Reference/Reference.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM