zoukankan      html  css  js  c++  java
  • 【每日技术点】13.12.13

    1、UITextView在UITableViewCell 中自适应高度的问题

     1 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
     2 {
     3    。。。。。。
     4 
     5 UITextView * contentView = [[UITextView alloc] initWithFrame:CGRectZero];
     6         contentView.textColor = [UIColor colorWithRed:80.0/255.0 green:132.0/255.0 blue:183.0/255.0 alpha:1.0];
     7         [contentView setFont:[UIFont systemFontOfSize:12.0f]];
     8         [contentView setBackgroundColor:[UIColor clearColor]];
     9         [contentView setEditable:NO];
    10         contentView.contentInset = UIEdgeInsetsMake(15,-8,0,18);//这句很重要,因为textview中的text也是有自己的边界的。
    11         [cellBgView addSubview:contentView];
    12         
    13         NSString *text = [contentArray objectAtIndex:[indexPath section]];
    14         CGSize constraint = CGSizeMake(200, 20000.0f);
    15         CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:12.0f] constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping];
    16         [contentView setFrame:CGRectMake(10, 10, 280, MAX(size.height, 44.0f))];
    17 
    18  }
    1 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    2 {
    3     NSString *text = [contentArray objectAtIndex:[indexPath section]];
    4     CGSize constraint = CGSizeMake(200, 20000.0f);
    5     CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping];
    6     CGFloat height = MAX(size.height, 44.0f);
    7     return height + (10 * 2);
    8 }
  • 相关阅读:
    【坐在马桶上看算法】算法5:解密回文——栈
    【坐在马桶上看算法】算法4:队列——解密QQ号
    【坐在马桶上看算法】小哼买书
    python项目离线环境配置指南
    vis.js绘图库的一个BUG以及源码修正
    Python 访问soap服务
    一些教训
    Django 图片上传、存储与显示
    WAMP的一些配置修改
    Alpha阶段个人总结
  • 原文地址:https://www.cnblogs.com/ymonke/p/3472990.html
Copyright © 2011-2022 走看看