我想让应用程序的语音泡泡,如果你有任何演示链接请与我分享,在这里我分享一个形象请帮助我 我有一个文本字段,然后这个文本字段文本在标签中设置动态高度和图像也设置动态高度宽度 在这里我分享图片链接请检查 link image screenshot 我面临的问题是我的代码
这是我的代码
-(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 :(得分:0)
我建议你使用可伸缩的图像并为每个图像定义合适的边缘插图。您可以轻松地将文本矩形包裹起来:
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 = ...;