문제

sqlite3 데이터베이스에서 텍스트를 표시하고 있으며 텍스트 양에 따라 UitextView가 자동으로 크기를 조정하려고합니다. 다음과 같이 잘 할 수 있습니다.

TextLabel.scrollEnabled = YES;
TextLabel.userInteractionEnabled = YES;

[TextLabel setFrame:CGRectMake(55.10, 26.15, TextLabel.contentSize.width, 
                                             TextLabel.contentSize.height)];

이것은 잘 작동합니다. 최대 높이를 설정하려고 할 때 어려움을 겪고 있습니다.

따라서 UitextView는 Maxiumum 높이에 도달하지 않는 한 텍스트로 크기를 조정합니다.이 경우 사용자는 나머지 텍스트를 보려면 스크롤 막대를 사용해야합니다.

모든 도움은 높이 평가 될 것입니다

도움이 되었습니까?

해결책

다음은 일부 멀티 린 텍스트에 대해 원하는 높이를 발견하는 방법입니다.

int myWidth = 300;
int maxHeight = 9999;
NSString *myString = @"lorem ipsum dolor yadda";
UIFont *myFont = [UIFont fontWithName:@"Helvetica" size:14];
CGSize myStringSize = [myString sizeWithFont:myFont 
                           constrainedToSize:CGSizeMake(myWidth, maxHeight)
                               lineBreakMode:textLabel.lineBreakMode];

textLabel.frame = CGRectMake(10, 10, myWidth, myStringSize.height);

나는이 이전 질문에 대한 Nevan의 답변에서 이것을 얻었습니다.

참조: NSString Uikit 추가에 대한 Apple의 문서.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top