2014-09-10 59 views
0

我想使氣泡像應用程序,如果你有任何演示鏈接請與我分享,在這裏我分享一個圖像,請幫助我 我有一個文本場,然後用動態的高度和形象也設置動態高度標籤設置該文本框的文字寬度 這裏我分享圖片鏈接請 link image screenshot 我已經面臨喪失的問題,這裏是我的代碼ios uitextfield獲取文本和管理標籤和圖像如何管理這

這裏是我的代碼

-(void)TextHeight 
{ 

    NSString *message = txtmain.text; 
    CGSize size = [message sizeWithFont:[UIFont fontWithName:fontName size:fontsize] constrainedToSize:CGSizeMake(lblTextInBubbles.frame.size.width, 9999.0f) lineBreakMode:NSLineBreakByCharWrapping]; 


    CGFloat height = size.height+60; 
    CGFloat width = size.width+50; 

    // NSLog(@"w== %f,, H==%f",width,height); 

    if(lblpositionwidth < 210) 
    { 
     if(lblPositionDynamicChange > 33) 
     { 
      lblPositionDynamicChange=lblPositionDynamicChange-3; 

     } 

     lblTextInBubbles.frame=CGRectMake(lblPositionDynamicChange, lblTextInBubbles.frame.origin.y, width, height); 

     lblpositionwidth=lblTextInBubbles.frame.size.width; 
    }else 
    { 
     if(lblTextInBubbles.frame.size.height < 125) 
     { 
      if(lblPositionDynamicChangeY > 38) 
      { 
       lblPositionDynamicChangeY=lblPositionDynamicChangeY-10; 

      } 
      lblTextInBubbles.frame=CGRectMake(lblTextInBubbles.frame.origin.x, lblPositionDynamicChangeY, lblTextInBubbles.frame.size.width, height); 
     }else 
     { 
      NSLog(@"%lu",(unsigned long)[lblTextInBubbles.text length]); 

     } 
    } 
    lblTextInBubbles.lineBreakMode=6; 
    // NSLog(@"After= %f",lblTextInBubbles.frame.origin.x); 
    [self setBubblesImageFrame]; 
} 
-(void)setBubblesImageFrame 
{ 
    imgbabble.frame = CGRectMake(lblTextInBubbles.frame.origin.x -55, lblTextInBubbles.frame.origin.y-55, lblTextInBubbles.frame.size.width+100, lblTextInBubbles.frame.size.height+100); 
} 

- (IBAction)txt_editing:(id)sender 
{ 
    [self TextHeight]; 
    lblTextInBubbles.textAlignment = NSTextAlignmentCenter; 
    /* if([txtmain.text length] > 16) 
    { 
     NSLog(@"x=%f,y=%f,,,,, width=%f,,,,height=%fds",imgbabble.frame.origin.x,imgbabble.frame.origin.y,imgbabble.frame.size.width,imgbabble.frame.size.height); 

     imgbabble.frame=CGRectMake(imgbabble.frame.origin.x-10, imgbabble.frame.origin.y-5, 160, 64); 
     // NSLog(@"x=%f,y=%f,,,,, width=%f,,,,height=%fds",imgbabble.frame.origin.x,imgbabble.frame.origin.y,imgbabble.frame.size.width,imgbabble.frame.size.height); 
    }*/ 
    lblTextInBubbles.text=txtmain.text; 
    lblTextInBubbles.textColor= [UIColor whiteColor]; 

    lblTextInBubbles.layer.borderColor=[UIColor whiteColor].CGColor; 
     lblTextInBubbles.layer.borderWidth=1.0; 

} 

回答

0

我建議你使用可拉伸的圖像,併爲每一個定義適當的邊緣插入。您可以輕鬆地將包裹你身邊文本RECT:

UIImage *bubbleImage = [[UIImage imageWithCGImage:[UIImage imageNamed:@"ImageBubble~iphone"].CGImage scale:1.0 orientation:UIImageOrientationRight] resizableImageWithCapInsets:UIEdgeInsetsMake(13, 13, 13, 21) resizingMode:UIImageResizingModeStretch]; 

UIImageView *bubbleImageView = [[UIImageView alloc] initWithImage:bubbleImage]; 
bubbleImageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; 
bubbleImageView.frame = ...; 

enter image description here

+0

如果您有任何演示鏈接,請給我樂於助人的我,否則我試試這個代碼 三江源......對我的幫助。 – 2014-09-11 05:52:32