zoukankan      html  css  js  c++  java
  • 简易聊天 汽包 自适应

    #pragma mark -  聊天气泡的自适应

    - (void)bubblesToCalculate{

        

        CGRect rect = [_field.text boundingRectWithSize:CGSizeMake(180, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin| NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:15]} context:Nil];

        

        CGSize size = rect.size;

        

        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-size.width-15, 5, size.width+15, size.height+15)];

        

        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, size.width+15, size.height+15)];

        

        UIImage *bgImg = [UIImage imageNamed:@"bubbleSelf"];

        

        UIImage *image = [bgImg stretchableImageWithLeftCapWidth:10 topCapHeight:10];

        

        imageView.image = image;

        

        [view addSubview:imageView];

        

        UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(5, 2, size.width, size.height+5)];

        lab.font = [UIFont systemFontOfSize:15];

        

        lab.numberOfLines = 0;

        

        lab.text =_field.text;

        

        view.tag = 10;

        

        [view addSubview:lab];

        

        [_messageArray addObject:view];

        

        [_bgView reloadData];

        

        _field.text = @"";

        

        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_messageArray.count - 1 inSection:0];

        

        [_bgView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];

        

        

        [_field resignFirstResponder];

        [UIView animateWithDuration:0.34 animations:^{

            _inputView.frame = CGRectMake(0, self.view.frame.size.height-60, SCREEN_WIDTH, 40);

            

        }];

        [lab release];

        [view release];

        [imageView release];

        

    }

  • 相关阅读:
    android开发:退出程序(对话框、两次返回键退出)
    【转】将HTML5封装成android应用APK 文件若干方法
    Linux语言修改
    Oracle用户常用数据字典
    成本控制:Oracle 优化器内幕
    [转]oraclemerge用法详解
    Show [SQL*Plus]
    【转】cron
    修改Linux主机名
    表空间删除
  • 原文地址:https://www.cnblogs.com/ysh-LOVE-hmx-5201314/p/4331056.html
Copyright © 2011-2022 走看看