【问题标题】:ios uitextfield to get text and manage label and image how to manage thisios uitextfield 获取文本并管理标签和图像如何管理
【发布时间】:2014-09-11 00:14:23
【问题描述】:

我想制作像应用程序一样的语音气泡,如果您有任何演示链接请与我分享,我在这里分享图片请帮助我 我有一个文本字段,然后这个文本字段文本设置在标签中,动态高度和图像也设置动态高度宽度 在这里我分享一个图片链接请检查 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;

}

【问题讨论】:

    标签: ios label bubble-sort


    【解决方案1】:

    我建议您使用可拉伸图像并为每个图像定义适当的边缘插图。您可以轻松地环绕您的文本矩形:

    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 = ...;
    

    【讨论】:

    • 如果你有任何演示链接,请给我它对我有帮助,否则我试试这个代码谢谢你...帮助我。
    猜你喜欢
    • 2020-03-24
    • 2012-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-15
    • 2011-03-24
    相关资源
    最近更新 更多