• 简易聊天 汽包 自适应


    #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];

        

    }

  • 相关阅读:
    莎士比亚名言
    庄子名言
    Javascript: 通过图片url获取图片blob对象
    toast提示 封装
    maya模型导入UE4,如何做到等比导入
    GPU渲染和CPU渲染农场成本对比
    C4D渲线框
    C4D教程笔记——高科技线框3D模型全息投影 X-Wing Hologram Animation
    arnold和redshift渲染器
    使用Redshift渲染器,怎么选电脑配置!
  • 原文地址:https://www.cnblogs.com/ysh-LOVE-hmx-5201314/p/4331056.html
Copyright © 2020-2023  润新知