2014-09-10 54 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