2011-09-30 11 views

답변

1

은 당신이 원하는 결과를 얻었다 생각 ...

// Create a size with large height, but matching width to UITextView. 
[myTextView setBackgroundColor:[UIColor greenColor]]; 
CGSize maxSize = CGSizeMake(myTextView.frame.size.width, 20); 

// Determine the size needed to display the text - we just need the new height. 
CGSize textSize = [myTextView.text sizeWithFont:myTextView.font constrainedToSize:maxSize lineBreakMode:UILineBreakModeWordWrap]; 

// Set the UITextView's frame to the new height. 
CGRect textViewRect = myTextView.frame; 
textViewRect.size.height = textSize.height+13; 
myTextView.frame = textViewRect; 
2

이와 비슷한?

textView.text = [textView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

0

난 당신이 친절하게 텍스트를 수용 할 수있는 UITextView의 크기를 조정하고자하는 추측/있으리라 믿고있어. 그렇다면, 나는 당신이 조사 제안 : 예를 들어

- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode; 

:

내가 하란으로 code.try 이상으로 업데이트 한
// Create a size with large height, but matching width to UITextView. 
CGSize maxSize = CGSizeMake(myTextView.frame.size.width, 9999); 

// Determine the size needed to display the text - we just need the new height. 
CGSize textSize = [myTextView.text sizeWithFont:myTextView.font constrainedToSize:maxSize lineBreakMode:UILineBreakModeWordWrap]; 

// Set the UITextView's frame to the new height. 
CGRect textViewRect = myTextView.frame; 
textViewRect.size.height = textSize.height; 
myTextView.frame = textViewRect; 
+0

전 - (CGSize) sizeWithFont : (UIFont *) font constrainedToSize : (CGSize) size lineBreakMode : (UILineBreakMode) lineBreakMode;를 작성해야합니다. .h 파일의 메소드? – PJR

+0

textViewRect.height = textSize.height; 행은 오류 – PJR

+0

을 표시합니다. 아니요, NSString 인스턴스 메서드이므로 인터페이스에 선언하지 않고 코드에 포함시킬 수 있습니다. –

관련 문제