博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UILabel 根据文本内容设置frame
阅读量:4977 次
发布时间:2019-06-12

本文共 1548 字,大约阅读时间需要 5 分钟。

  CGRect senderFrame = cell.senderLabel.frame;

    CGRect creatAtFrame = cell.creatAtLabel.frame;
    CGSize senderSize = [cell.senderLabel.text sizeWithAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Heiti SC" size:15.0]}];
    senderFrame.size.width = ceil(senderSize.width);
    if (senderFrame.size.width>0) {
        senderFrame.size.width=ceil(senderSize.width)+10;
    }
    
    if (senderFrame.size.width>200) {
        senderFrame.size.width = 200;
    }
    
    cell.senderLabel.frame = senderFrame;
    creatAtFrame.origin.x = CGRectGetMaxX(cell.senderLabel.frame)+10;
    cell.creatAtLabel.frame = creatAtFrame;
    
    NSDictionary *info = messageModel.info;
    // 设置属性来设置行高
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = 3;
    NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:15.0],NSParagraphStyleAttributeName:paragraphStyle};
    CGFloat width = CGRectGetWidth(self.view.frame)-CGRectGetMinX(cell.senderLabel.frame) - 16;
    CGRect frame = cell.descLabel.frame;
    frame.size.width = width;
    
    cell.descLabel.emojiDelegate = self;
    [cell.descLabel sizeToFit];
    
    //    cell.descLabel.text = info[@"message"];
    [cell.descLabel setEmojiText:messageModel.timeViewStr];
    
    CGRect bodyFrame = CGRectMake(0, 0, 0, 0);
    //    if (cell.descLabel.text!=NULL) {
    bodyFrame = [cell.descLabel.text boundingRectWithSize:CGSizeMake(width, 500) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil];
    frame.size.height = ceil(bodyFrame.size.height);
    cell.descLabel.frame = frame;

转载于:https://www.cnblogs.com/frounk/p/5841329.html

你可能感兴趣的文章