2012-07-13 2 views
0

나는이 방법에 대한 모든 게시물이 너무 좋아 보인다. 그리고 많은 포스터 답변은 단지 높이 제한으로 정말로 큰 값을 넣는 것입니다.NSString sizeWithFont constratinedToSize with NIAttributedLabel을 어떻게 적절하게 사용합니까?

그러나 나를 위해 이것은 작동하지 않습니다. 이건 내 코드입니다 :이 방법은 내가 잘못된 크기가 NSString의 일부입니다 생각하는 것을 반환하기 때문에 내가 NIAttributedLabel을 사용하고

//Create the contentLabel Label 
    CGSize size = [contentText sizeWithFont:[UIFont fontWithName:@"Helvetica" size:14] constrainedToSize:CGSizeMake(286, 9999) lineBreakMode:UILineBreakModeWordWrap]; 

    //Create the content label with its position 7 pixels below the title 
    contentLabel = [[NIAttributedLabel alloc] initWithFrame: 
        CGRectMake(7, titleContainerView.frame.origin.y + 7, 286, size.height)]; 

    //Set the provided text and the font 
    contentLabel.font = [UIFont fontWithName:@"Helvetica" size:14]; 
    contentLabel.numberOfLines = 0; 
    contentLabel.lineBreakMode = UILineBreakModeWordWrap; 
    contentLabel.text = contentText; 

이 정말 영향을주지해야한다고 생각. 나는 큰 높이 제약이 을 위해 무엇 그게 생각하지만 방법이, 때로는 문자열을 자릅니다 나는 애플의 문서에서 읽었다

편집 : 나는이 문제에 있음을 발견했습니다 NIAttributedLabel, 일반 UILabel을 사용하면 완벽하게 작동합니다. 여기 내 문제를 보여주는 두 개의 소스 문자열과 해당 스크린 샷, 첫 번째는, 결정, 다른 하나는 괜찮을하기 :

"Buying a Mobile\nHello - I'd like a Motorola Defy with a Smartphone 60 Plan.\nBroadband Problem\nMy Broadband’s out. I've tested the router and cables and ruled out my equipment. Is there a problem at your end?"

Screenshot 1

"Buying a Mobile\nI\'m Mrs Sina Manu-Harris. My account number is 156205169. I\'m going overseas in 6 months time on the 2nd of September and I\'d like to get organized in advance and buy a new mobile phone.\nBroadband Problem\nGood afternoon. It’s Mrs Sina Manu-Harris here. My account number is 156205169. My Broadband isn’t working. I’ve checked my network and phone cables and I've also checked my filters."

Screenshot 2

+0

어떻게 작동하지 않는지 설명하십시오. 스크린 샷이 도움이 될 것입니다. 라벨의 최종 높이가 실제로 'sizeWithFont'에서 결정된 높이인지 확인해 보셨습니까? 어쩌면 NIAttributedLabel 구현에 몇 가지 단점이있을 수 있습니다. –

+0

나는 심지어 UILabel과 비슷한 문제가있다 ... – Bharathi

답변

0

당신이 할 수있는 ' CoreText와 동일한 글리프 배치 알고리즘을 사용하여 NSString에 의존합니다. NIAttributedLabel 크기를 조정할 때는 CoreText를 사용하여 레이블의 이상적인 크기를 결정하기 때문에 레이블 sizeToFitsizeThatFits: 메서드를 사용하는 것이 좋습니다.

0

문자열 "T \ nT \ nT"로 확인하십시오. @ "T \ nT \ n"만 인쇄됩니다. _textFrame은 3 개가 아닌 2 개의 보이는 선만 표시합니다. I는 sizeWithFont를 사용하는()로 사용

NISizeOfAttributedStringConstrainedToSize을 :

1

NimbusKit 1.0 NIAttributedLabel 높이를 계산하는 새로운 방법을 제공하며와 동일한 문제가 발생. 새로운 방법이 나를 위해 완벽하게 작동했습니다. (내 attriubited 레이블에 이미지가 없습니다)

관련 문제