나는이 방법에 대한 모든 게시물이 너무 좋아 보인다. 그리고 많은 포스터 답변은 단지 높이 제한으로 정말로 큰 값을 넣는 것입니다.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?"
"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."
어떻게 작동하지 않는지 설명하십시오. 스크린 샷이 도움이 될 것입니다. 라벨의 최종 높이가 실제로 'sizeWithFont'에서 결정된 높이인지 확인해 보셨습니까? 어쩌면 NIAttributedLabel 구현에 몇 가지 단점이있을 수 있습니다. –
나는 심지어 UILabel과 비슷한 문제가있다 ... – Bharathi