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

        

    }

  • 相关阅读:
    fn project 试用之后的几个问题的解答
    fn project 扩展
    fn project 生产环境使用
    fn project 对象模型
    fn project AWS Lambda 格式 functions
    fn project 打包Function
    fn project Function files 说明
    fn project hot functions 说明
    fn project k8s 集成
    fn project 私有镜像发布
  • 原文地址:https://www.cnblogs.com/ysh-LOVE-hmx-5201314/p/4331056.html
Copyright © 2011-2022 走看看