温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

cell自动换行

发布时间:2020-07-10 14:07:47 来源:网络 阅读:479 作者:卓行天下 栏目:开发技术

cell自动换行

#import "HistoryMessageViewController.h"

#import "UITableView+FDTemplateLayoutCell.h"

#import "HistoryMessageCell.h"



#define FONT_SIZE 14.0f

#define CELL_CONTENT_WIDTH 320.0f

#define CELL_CONTENT_MARGIN 10.0f




#define ScreenWidth [UIScreen mainScreen].bounds.size.width

#define ScreenHeight [UIScreen mainScreen].bounds.size.height





#define FONT_NAME @"Heiti SC"

@interface HistoryMessageViewController ()<UIActionSheetDelegate>



{

    NSMutableArray *myCells;// cell数组

    

}

@property (nonatomicstrongNSMutableArray *feedEntitySections;

@property (nonatomicassignBOOL cellHeightCacheEnabled;

@property(nonatomic,strong)NSArray*  tableData;


@end


@implementation HistoryMessageViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    [self loadBackItem];

    self.title = @"历史评价";

    

    self.tableData = @[

                       @" 中国网326日讯 据外媒报道,当地时间325日,法国总统奥朗德,德国总理默克尔、西班牙首相拉霍伊共同抵达德国之翼航空公司客机的失事地点。报道称,三位国家领导人抵达当地以后,与参加搜救的工作人员在临时指挥中心进行了会面。此外,法、德、西三国领导人在客机坠毁地点附近对在此次空难中的遇难者表示哀悼,并对参与搜救的消防队员表示了感谢。",

                       @"大量的文物流失,频频的文物破坏已成为中国文物保护工作的常年之痛。中国文物保护立法已经30多年,今天,除了相关部门对文物保护的漠视和不作为,我们剩下的只有那些越来越少的沉默的文物。",

                       @"当地时间2015325日,乌克兰基辅,在记者、摄影师及一众高官的注视之下,乌克兰警方冲入一场电视转播的内阁会议现场,逮捕乌克兰紧急服务部部长Serhiy Bochkovsky及其副手Vasyl Stoyetsky,两人均被控高层次腐败。据乌克兰内政部长表示,被捕的两人涉嫌多付给包括俄罗斯石油巨头卢克石油公司在内的多家公司采购费用。",

                       @"四川峨眉山景区降近7年来最大雪",

                       @"萌物:伊犁鼠兔是世界珍稀动物之一。日前,这一天然萌物再次在中国新疆被发现。伊犁鼠兔,生活在天山山脉高寒山区,是中国新疆特有的一个物种。323日,实名认证微博美国国家地理发布一组有关伊犁鼠兔的照片,因其形象呆萌可爱,长相酷似泰迪,立即引起了众多网友的关注。23日中午,记者电话联系到新疆发现鼠兔第一人,新疆环境保护科学研究院副研究员、新疆生态学会副秘书长李维东,他义务跟踪保护鼠兔三十多年。李维东介绍,美国国家地理微博晒出的这组鼠兔照片,是他去年7月在天山精河县木孜克冰达坂布设红外线触发相机时摄到的。照片中的鼠兔,也是他时隔24年后再次拍摄到的珍贵镜头。"

                       ];

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    

     return 1;

    

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

  

       return self.tableData.count;

 

}


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

    

   NSString *text = [_tableData objectAtIndex:[indexPath row]];

//

//   // CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);

//    

////    CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping];

////    

//    

//    CGSize size =[text boundingRectWithSize:CGSizeMake(305*ScreenWidth/375,ScreenHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15*ScreenWidth/375]} context:nil].size;

//    

//    CGFloat height = MAX(size.height, 44.0f);

//    

//    return height + (CELL_CONTENT_MARGIN * 2);

//    

//    static NSString *customCellIndentifier = @"HistoryMessageCell";

//    

//    HistoryMessageCell *cell = (HistoryMessageCell *)[tableView dequeueReusableCellWithIdentifier:customCellIndentifier];

//    

//    

//    if(cell == nil){

//        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"HistoryMessageCell" owner:self options:nil];

//        cell = [nib objectAtIndex:0];

//    }

    //设置点击没有变色

     // cell.selectionStyle = UITableViewCellSelectionStyleNone;

//    cell.haolb.text=[self.tableData objectAtIndex:indexPath.row];

//    cell.haolb.lineBreakMode = NSLineBreakByWordWrapping;

//    cell.haolb.numberOfLines = 0;

//    [cell setNeedsUpdateConstraints];

//    [cell updateConstraintsIfNeeded];

//

//     CGSize cell =[text boundingRectWithSize:CGSizeMake(305*ScreenWidth/375,ScreenHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15*ScreenWidth/375]} context:nil].size;

    

       // cell.bounds = CGRectMake(0.0f, 0.0f, CGRectGetWidth(tableView.bounds), CGRectGetHeight(cell.bounds));

    

    //算出label的行数和高度

        CGSize size =[text boundingRectWithSize:CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 99999.0foptions:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:FONT_SIZE]}context:nil].size;

    

    

    

//    [cell setNeedsLayout];

//    [cell layoutIfNeeded];

//

//    CGFloat height = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;

//    height += 1;

//    return height;

    

    

    CGFloat height = MAX(size.height44.0f);

    //

    return height + (CELL_CONTENT_MARGIN * 13);


}


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


    static NSString *customCellIndentifier = @"HistoryMessageCell";

 

    HistoryMessageCell *cell = (HistoryMessageCell *)[tableView dequeueReusableCellWithIdentifier:customCellIndentifier];

    

    if(cell == nil){

        NSArray *nib = [[NSBundle mainBundleloadNibNamed:@"HistoryMessageCell" owner:self options:nil];

        cell = [nib objectAtIndex:0];

    }

    

    //设置点击没有变色

     cell.selectionStyle = UITableViewCellSelectionStyleNone;

     cell.haolb.text=[self.tableData objectAtIndex:indexPath.row];

     cell.haolb.lineBreakMode = NSLineBreakByWordWrapping;

     cell.haolb.numberOfLines = 0;

     [cell setNeedsUpdateConstraints];

     [cell updateConstraintsIfNeeded];

    

    

    

        return cell;

    

}


@end


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI