1

내용에 따라 가변 크기 텍스트 상자를 지원하는 응용 프로그램을 만들려고합니다. UITextView의 크기는 최대 4 줄까지 증가한 다음 스크롤을 활성화해야합니다.UItextView에서 줄 수 얻기

텍스트를 입력 할 때 줄 수를 얻을 수 없습니다.

제발 할 방법을 제안 해주세요. 모든 샘플 코드 스 니펫은 매우 높이 평가 될 것입니다.

미리 감사드립니다.

+0

가능한 복제 [라인의 UITextView 번호를 찾는 방법 (https://stackoverflow.com/questions/7320361/how-to-find-uitextview-number-of-lines) – iWheelBuy

답변

3

이 문제에 대한 임시 해결책을 하나 시도했습니다. 하나는 다음 코드 조각을 -보기 컨트롤러에 추가하고 IB의 파일 소유자에게 위임자를 변경할 수 있습니다.

float adjustvar; 
    if ([textView.text isEqualToString:@""]) { 
     //change these values according to your requirement as they are hard coded to adjust cursor and size of the textview 
     adjustvar = 37.0; 
     textView.contentInset = UIEdgeInsetsMake(6 ,0 ,0 ,0); 
    } 
    else { 
     adjustvar = textView.contentSize.height; 
    } 

    CGRect temp = textView.frame; 
    temp.origin.y = textView.frame.origin.y + textView.frame.size.height - adjustvar; 
    temp.size.height = adjustvar; 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.4]; 
    [UIView setAnimationsEnabled:YES]; 

    if (temp.size.height > 142.0) { 
     textView.scrollEnabled = YES; 
    } 
    else { 
     textView.scrollEnabled = NO; 
     textView.frame = temp; 
    } 

    [UIView commitAnimations];` 

희망이 있습니다. 더 나은 해결책이 친절하게 도움이된다면.

감사