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 }
  • 相关阅读:
    冒泡排序及优化
    Map的三种遍历
    抽象类以及接口的异同
    安卓仿制新浪微博(一)之OAuth2授权接口
    安卓handler.post问题
    Git——版本控制器概述
    Linux概述及简单命令
    JBoss7配置-支持IPv4和IPv6双栈环境
    作用域public,private,protected,以及不写时的区别
    UML类图画法及类之间几种关系
  • 原文地址:https://www.cnblogs.com/ymonke/p/3472990.html
Copyright © 2011-2022 走看看