2012-07-25 2 views
0

UIView의 하위보기로 UITextView가 있습니다. UIView를 화면 아래쪽에 배치했습니다. 뷰 컨트롤러에는 UITabViewController가 있습니다. 내가 UITextView의 내부 텍스트를 기반으로 UITextView 높이를 높이려는UITextView의 콘텐츠 크기에 따라 UIView의 Y 축을 동적으로 변경하는 방법

toolBarView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 330, 320, 40)]; 
[self.view addSubview: toolBarView1]; 
TextView1 = [[UITextView alloc] initWithFrame:CGRectMake(35, 7.5, 210, 25)]; 
textViewImageView1 = [[UIImageView alloc]initWithFrame: CGRectMake(0, 0, 210, 25)]; 
[TextView1 addSubview: textViewImageView1]; 
[toolBarView1 addSubview: TextView1]; 

, 아래와 같이 UIView의에 프레임 크기를했다. 나는

CGRect frame = messageTextView1.frame; 
    frame.size.height = messageTextView1.contentSize.height;  

    NSLog(@"TextViewHeight With Texts : %f", frame.size.height); 
    int height = frame.size.height; 
    NSLog(@"TextViewHeight With Texts : %d", height); 

    height = height + 10; 
    NSLog(@"Height Plus 10 : %d", height); 
    height = 370 - height; 
    NSLog(@"ToolBarView1 Y axis : %d", height); 


    messageTextView1.frame = frame; 
    textViewImageView1.frame = CGRectMake(0, 0, messageTextView1.frame.size.width, messageTextView1.frame.size.height); 
    toolBarView1.frame = CGRectMake(0, height, 320, messageTextView1.frame.size.height+10); 

내가 화면 자체의 UIView의 및 UITextView 바닥을 배치 할 코드 아래에 다음을 사용했다하지만 난 UITextview 높이에 따라 UIView의 및 UITextview하고있는 UIView의 Y 축의 높이를 높이려는 . 누구든지이 일을 도와 줄 수 있습니까? 미리 감사드립니다.

답변

0

당신은 다음 textViewFrame

에서 uitextview 높이를 얻을 수있는이
 
    CGFloat constrainedSize = 252.0f;//your uitextview widght 
    UIFont * myFont = [UIFont fontWithName:@"Arial" size:19];//your uitextview font 
    CGSize textSize = [dis.text sizeWithFont: myFont 
          constrainedToSize:CGSizeMake(constrainedSize, CGFLOAT_MAX) 
           lineBreakMode:UILineBreakModeWordWrap]; 
    CGRect textViewFrame = CGRectMake (0, 0, textSize.width, textSize.height);

같은 uitextview 높이의 미리보기를 얻을 수 있습니다
관련 문제