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 }
  • 相关阅读:
    集合异常原因与处理方式
    List的子类特点
    数据结构:数据的组织方式
    java对多态的了解
    JAVA电话本系统
    字符串转换数组
    登录用户名密码是否合法
    十三 spark 集群测试与基本命令
    十二 flume与kafka数据传输
    十一 spark- Standalone 集群
  • 原文地址:https://www.cnblogs.com/ymonke/p/3472990.html
Copyright © 2011-2022 走看看