2011-12-05 4 views
2

XML 피드에서 UITextView를로드하므로 텍스트가 계속 변경됩니다. 셀 및 텍스트의 크기를 조정하려면 다음을 시도하고 텍스트보기가 아닌 셀의 크기를 조정합니다. 텍스트보기를 표시하지 않거나 때로는 일부만 표시합니다.UITextView 동적으로 텍스트 상자/셀 크기 조정

올바른 방법으로 어떤 조언을 주시면 감사하겠습니다.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 

    AssessObject *newObj1; 
    newObj1=[totalArray objectAtIndex:indexPath.row]; 

    NSString *cellText = newObj1.routeText; 

    UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:16.0]; 
    CGSize constraintSize = CGSizeMake(188.0, CGFLOAT_MAX); 
    CGSize textViewSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap]; 


    return textViewSize.height + 200; 


} 

답변

3

셀에 추가 한 UITextView의 AutoresizingMask를 확인하십시오. 는 셀의 크기를 조정하도록

확인이 설정을 확인합니다 UITextView의

+0

이제는 크기에 맞춰 크기가 조정되었지만 셀의 다시 그리기/원본 그리기는 정말 이상합니다. 처음에는 화면에 반으로 나타났습니다. 아래로 스크롤하면 전체 텍스트가 나타납니다. – TMB87

+0

http://screencast.com/t/cxXaac0bPw 내 말을 설명하는 비디오입니다. – TMB87

+0

scaleToFit 모드에 대해 말하지 않았습니다. 그러나 [autoresizingMask] (http://www.techotopia.com/images/2/27/Iphone_view_autosize_height_width.jpg); 수퍼 뷰에 따라 크기가 조정되도록 여기에 모든 설정이 올바르게되어 있는지 확인하십시오. 그건 그렇고, 당신의 스크린 캐스트를 본 후에도 나에게 보인다. UITableViewCells의 재사용 메커니즘을 오용하기 때문일 수도있다. – AliSoftware

0

설정 글꼴 크기, 텍스트 내용 및 프레임 RECT (당신은 UIViewAutoresizingMaskFlexibleWidth|UIViewAutoresizingMaskFlexibleWidth 값을 사용하여 하나 IB에, 또는 코드를 통해이 작업을 수행 할 수 있습니다) , [UITextView sizeToFit]을 입력하여 UITextView의 contentSize을 계산 한 다음 contentSize 크기로 행 높이를 계산합니다.

UITextView의 프레임 rect의 크기를 조정하는 것을 잊지 마십시오.

1

textView의 크기를 textView의 contentSize와 같게 설정하십시오. 이 같은 뭔가 :

CGRectMake(textView.frame.origin.x, textView.frame.origin.y, textView.frame.size.width, textView.contentSize.height); 

는 나는있는 contentView의의 높이와 동일하게 텍스트 뷰의 높이를 만들고 있어요.

0

나는 ScrollView에 넣을 때 텍스트 양에 따라 TextView의 크기를 조정하기 위해 Bruno의 아이디어를 사용했습니다. 이것이 제가하는 방법입니다. 거기에 상수의 무리, 당신이 사용할 수 없습니다. textView를 ScrollView에 추가 한 후에 크기를 조정하는 것이 중요합니다. 당신은 텍스트 뷰의 크기를 변경하고 이전 센터로 중앙하려면

// Programmatic creation of scroll view layout 
NSString *text = @"Your text"; 
CGFloat textOffSetInColumn = 10; 
CGFloat infoTextWidth = 196; 
CGFloat infoOffsetVertical = 36; 
CGFloat initialTextHeight = 50; 

// Create textView with initial height 
CGRect infoTextFrame = CGRectMake(textOffSetInColumn, infoOffsetVertical, infoTextWidth, initialTextHeight); 
infoTextView = [[UITextView alloc] initWithFrame:infoTextFrame]; 
infoTextView.text = text; 
[scrollView addSubview:infoTextView]; 

// Resize textView 
CGFloat infoTextHeight = infoTextView.contentSize.height; 
infoTextFrame = CGRectMake(textOffSetInColumn, infoOffsetVertical, infoTextWidth, infoTextHeight); 
infoTextView.frame = infoTextFrame; 

,이 코드를 사용할 수 있습니다 대신 categoryTextView 자신 아울렛 이름을 사용의

// Changing size of TextView and centering 
    CGPoint center = self.categoryTextView.center; 
    self.categoryTextView.frame = CGRectMake(_categoryTextView.frame.origin.x, _categoryTextView.frame.origin.y, _categoryTextView.frame.size.width, _categoryTextView.contentSize.height); 
    self.categoryTextView.center = center; 

합니다.

관련 문제