2013-09-23 2 views
0

https://developer.apple.com/library/ios/documentation/uikit/reference/NSString_UIKit_Additions/Reference/Reference.html#//apple_ref/occ/instm/NSString/sizeWithAttributes에서 ::당신이 제공 한 TTF에 대해 UIFont를 얻는 현재 iOS의 현재 방법은 무엇입니까?

 
UITextAttributeFont 
Key to the font in a text attributes dictionary. 
The corresponding value is an instance of UIFont. 
Use a font with size 0.0 to get the default font size for the current context. 
Available in iOS 5.0 and later. 
Deprecated in iOS 7.0. 
Declared in UIStringDrawing.h. 

되는 "..."나는 텍스트의 특정 한 줄 문자열에 대한 폭 (높이도 원하는) 얻기 위해 노력하고, 이것은 내가 지금 무엇을 무엇 글꼴을 적절하게 초기화해야합니다. 이 메서드는 불완전합니다 (값을 반환하지 않음). 그러나 비 한정적인 방법으로 글꼴 정보를 지정하고 그려지는 문자열의 너비가 몇 픽셀인지 확인합니다.

-(float)getLength:(NSString *)text 
{ 
    CGSize size = [text sizeWithAttributes:[[NSDictionary alloc] initWithObjectsAndKeys:...]; 
} 

는 의미가 "당신이 마지막 호출을 만들 때 글꼴 세부 사항을 지정합니다" "한 번 글꼴 세부 사항을 지정, 그리고 당신이 다른 것으로 변경할 때까지가 유효합니다"로 변경 했습니까? 난 그냥 몇 일 전에 내 자신의 작품에 대한 당신의 문제에 정말로 문제가보고 된

답변

1

감사합니다.

찾고있는 전화 (궁극적 인 문제를 해결할 것입니다)는 "boundingRectWithSize: options: attributes: context:"이며 여기에서 UIFont you loaded (from your TTF file)을 속성으로 전달합니다.

더 나은하는 NSAttributedString은 또는 다음 글꼴과 글꼴 스타일의 혼합으로 텍스트 폭과 높이를 계산할 수 있기 때문에 또한, "boundingRectWithSize: options: context:" method있다 NSMutableAttributedString (.

를 사용