2012-09-16 2 views

답변

3

Apple은 UIKit 프레임 워크에 이것을 포함 시켰습니다. sizeWithFont : 메소드 또는 그 변형 중 하나를 사용하여 주어진 글꼴로 문자열의 크기를 계산할 수 있습니다.

NSString *testStr = @"This is a test string"; 
CGSize strSize = [testStr sizeWithFont:[UIFont boldSystemFontOfSize:16]]; 
CGFloat width = strSize.width; 

그 예에서 을 가지고 레이블의 폭과 비교 :

다음은 예입니다. https://developer.apple.com/library/ios/#documentation/UIKit/Reference/NSString_UIKit_Additions/Reference/Reference.html

1

사용

[UILabel의 텍스트] sizeWithFont : defaultFont constrainedToSize : defaultSize lineBreakMode : UILineBreakModeWordWrap]

방법

여기

는 문서이다
관련 문제