2011-08-30 4 views
0

내비게이션 컨트롤러를 통해 화면에 푸시 된 뷰가 있습니다.UIScrollView 및 UITextView 자동 크기 조정이 가능합니까?

내부는 UIScrollView입니다.

UIScrollView 내부에는 이미지 및 레이블과 같은 몇 가지 정적 개체가 있습니다.

그런 다음 하드 비트가옵니다. 길이가 다른 여러 텍스트 파일에서 텍스트가로드 된 UITextView가 있습니다.

내용에 UITextView 크기를 동적으로 할당 할 수 있어야하며 UIScrollView에도 동일한 크기가 있어야합니다. 이것이 가능한가?

+0

UITextView를 편집 할 수 있습니까? – jin

답변

1
float length = [yourText length]; 
textview.frame = CGRectMake(44, 87, 923, ceilf(length/142)*25); 

텍스트 폰트 폭 상정 된 상수 값이다. 이것에서 scrollview 프레임 참조를 textview 프레임으로 설정할 수 있습니다.

0

예를 이런 식으로 뭔가를 할 수 다음 int를 들어

if ([textView length] > int//any number you want) { 
    textView.frame = CGRectMake(//just adjust the size an position here); 
    scrollView.contentSize = CGSizeMake(//adjust scrollView size) 
} 
else if ([textView length] > int//just another number) { 
    // you can continue looping that for how often you want 
} 

을 당신이 텍스트는 시간을 확인 if 문. scrollView와 textView의 크기를 조정한다는 점을 기반으로합니다. 도움이 되었기를 바랍니다.

+0

해달라고 생각하면 효과가 있다고 생각합니다. 텍스트가 넘칠 경우가 아닙니다. – Rollo

+0

그게 무슨 뜻입니까? – JonasG

1

다음 코드를 사용하여이를 수행 할 수 있습니다.

난 당신이 텍스트 필드의 도움을 당신이있는 ScrollView

을 위해 할 수있는

NSString *cellText = "Text Of Your Text-Field"; 
UIFont *cellFont = [UIFont fontWithName:@"Your Font Name" size:FONT_SIZE];//UIFont *cellFont = [UIFont fontWithName:@"Helvetica-Bold" size:13.0]; 
CGSize constraintSize = CGSizeMake(@"Width Of Your Text-Field", MAXFLOAT);//CGSize constraintSize = CGSizeMake(220.0f, MAXFLOAT); 
CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap]; 

int height = labelSize.height; 

frame.origin.x = Starting Position of X; 
frame.origin.y = Starting Position of Y; 
frame.size.width = Width Of Your TextField; 
frame.size.height = height; 

UILabel *lblName = [[[UILabel alloc] initWithFrame:frame] autorelease]; 
lblName.numberOfLines = 0; 
lblName.lineBreakMode = UILineBreakModeWordWrap; 
lblName.textAlignment = UITextAlignmentLeft; 
lblName.textColor = [UIColor whiteColor]; 
lblName.backgroundColor = [UIColor clearColor]; 
lblName.font = [UIFont boldSystemFontOfSize:13.0]; 

과 같은 방법으로 그렇게 할 수 라벨과 같은 방법에 대한 해당 코드를했던 그냥 scrollview의 프레임을 설정해야하며 완료되었습니다.

고맙습니다 ...... 여기서 25

관련 문제