2017-01-18 4 views
0

을 사용하여 View에서 하나의 UITextview Custom 컨트롤을 만들었습니다. 정상적으로 작동합니다. 새 줄 텍스트보기를 입력하면보기 (진한 파란색)와 함께 증가합니다.이 TextViell이 스크롤 한 후에 작동합니다.UITextView의 크기를 조정하는 방법 단일 행만있는 경우 다중 행에서보기

코드입니다

-(void)setTextViewHeight 
{ 
    self.oldFrameHeight = self.commentTextView.frame.size.height; 
    CGFloat fixedWidth = self.commentTextView.frame.size.width; 
    CGSize newSize = [self.commentTextView sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)]; 
    CGRect newFrame = self.commentTextView.frame; 
    newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height); 
    self.commentTextView.frame = newFrame; 
    self.newFrameHeight = newFrame.size.height; 
    NSLog(@"Old Frame %f",self.oldFrameHeight); 
    NSLog(@"New Frame %f",self.newFrameHeight); 
} 
- (void)textViewDidChange:(UITextView *)textView 
{ 


    self.oldFrameHeight = textView.frame.size.height; 


    if(!(self.oldFrameHeight >= 44)) 
    { 
     [self setTextViewHeight]; 

     if (self.newFrameHeight > self.oldFrameHeight) 
     { 
      [self sabViewFrameChange]; 
     } 
    } 
    else if ([textView.text isEqualToString:@""]) 
    { 
     [self.commentTextView setFrame:CGRectMake(60, 10,self.frame.size.width - 130, 30)]; 

     UIViewController *controller=(UIViewController *)self.delegate; 
     self.frame = CGRectMake(0,controller.view.frame.size.height - 50, controller.view.frame.size.width,50); 
     self.height = 50; 
    } 
    else 
    { 
     self.commentTextView.scrollEnabled = YES; 
    } 
} 

내 질문

내가 크기는 그대로, 내가 선으로 감소하지 않았다 유지됩니다 UITextView에서 두 번째 줄을 제거한

.

도와주세요. 미리 감사드립니다.

이미지는 한 줄

enter image description here

더보기 두 개의 라인

enter image description here

2)

1) 어떻게 그것을 해결할 수있다? 어느 하나 어떤 생각이있어?

+0

이전 질문에 대한 답변도이 문제를 관리하십시오. 만약 당신이 한 줄을 가지고 있다면 그 줄 또한 한 줄의 데이터를보기 위해 설정합니다. 내 대답을 확인하십시오 http://stackoverflow.com/a/41676540/6656894 –

+0

No No 버디 그게 옳았습니다. 나는 아주 잘 이해했다. 그러나 문제는 내가 전화 할 때마다 그 부분을 사용한다면 의심의 여지가 없다. 그에 따라 textview의 크기를 조정하지만 여기서는 불가능합니다. – user7018875

+0

@Himanshu Moradiya : - 나는 단지 3 개월 만 더 예일뿐입니다. 그래서 정확한 해결책을 찾을 수 없습니다. 문제가되고 싶지 않다면 이메일로 보내주십시오. 데모 코드를 보내주십시오. – user7018875

답변

1

선언 numLinesInTextView 변수

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text; 
{ 
    NSLog(@"%@",text); 
    if ([text isEqualToString:@"\n"]) { 
      NSLog(@"New line"); 
    }else{ 
     int numLines = [textView intrinsicContentSize].height/textView.font.lineHeight; 
     NSLog(@"%f",textView.font.lineHeight); 

     numLinesInTextView = numLines; 
     if (numLinesInTextView == 0) { 
      [self.commentTextView setFrame:CGRectMake(60, 10,self.frame.size.width - 130, 30)]; 
      UIViewController *controller=(UIViewController *)self.delegate; 
      self.frame = CGRectMake(0,controller.view.frame.size.height - 50, controller.view.frame.size.width,50); 
      height = 50; 
      numLinesInTextView = 0; 
     } 

    } 
    return YES; 
} 

프로젝트에이 방법을 추가하고 그 작업을 완전히 벌금을 확인합니다. 지금.

해피 코딩.

+1

고마워 그것은 작동합니다 – user7018875