zoukankan      html  css  js  c++  java
  • ios开发之根据内容行数调整cell 高度,与label高度

    设置cell高度

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

    {

         NoticeMessage* msg = [arrayNoticeMessage objectAtIndex:indexPath.section];//取出对应的section或者cell

        UIFont *msgFont = [UIFont fontWithName:@"arial" size:15];//设置字体与字号

        //定义行高

        uint textLineheight = [@"The brown fox jumps over the lazy dog" sizeWithFont:msgFont constrainedToSize:CGSizeMake(MAXFLOAT, MAXFLOAT)].height;

        //设置内容高度

        CGSize infoSize = [msg.strContent sizeWithFont:msgFont constrainedToSize:CGSizeMake(170, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];

        return  infoSize.height;

    设置label高度,在下面方法中

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

    {

        static NSString *DetailCellIdentifier = @"ValueDetailCell";

        

        static NSString *SimpleCellIdentifier = @"ValueDetailSimpleCell";

        

        NSLog(@"section %d",indexPath.section);

        //带图的信息

        NoticeMessage* msg = [arrayNoticeMessage objectAtIndex:indexPath.section];

            DetailInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:DetailCellIdentifier];

            

            if (cell == nil) {

                cell = [[DetailInfoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DetailCellIdentifier];

            }

            cell.contentView.layer.cornerRadius = 3;

            cell.contentView.layer.masksToBounds = YES;

            cell.contentView.layer.bounds = CGRectMake(0, 0, cell.contentView.frame.size.width, cell.contentView.frame.size.height-50);

            cell.contentView.backgroundColor = [UIColor colorWithWhite:0.8 alpha:0.3];

            

            cell.InfoDate.text = msg.strDate;

            cell.InfoTitle.text = msg.strTitle;

            cell.InfoContent.text = msg.strContent;

            //cell.InfoDate.text = msg.strTimeStamp;

            cell.backgroundColor = [UIColor clearColor];

        

        //设置label的高度;

            UIFont *msgFont = [UIFont fontWithName:@"arial" size:15];

            CGSize infoSize = [msg.strContent sizeWithFont:msgFont constrainedToSize:CGSizeMake(170, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];

            CGRect frame = cell.InfoContent.frame;

            frame.size.height = infoSize.height;

            [cell.InfoContent setFrame:frame];

        

            return cell;

    }

  • 相关阅读:
    LowercaseRoutesMVC ASP.NET MVC routes to lowercase URLs
    Asp.net MVC Combres的简单用法
    原码, 反码, 补码 详解
    四种数据存储结构---顺序存储 链接存储 索引存储 散列存储
    快速排序时间复杂度为O(n×log(n))的证明
    进程与线程及其区别
    linux c语言定时器
    平衡二叉查找树的一些知识总结
    C++编程练习(17)----“二叉树非递归遍历的实现“
    C++编程练习(16)----“排序算法 之 快速排序“
  • 原文地址:https://www.cnblogs.com/tuhaoYY/p/3891750.html
Copyright © 2011-2022 走看看