小秋的家

          home

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            1 Posts :: 91 Stories :: 17 Comments :: 0 Trackbacks
          1. 動態調整UITableViewCell高度的實現方法 
          - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
              static NSString *CellIdentifier = @"Cell";
              UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
              if (cell == nil) {
                  cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
                  UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
                  label.tag = 1;
                  label.lineBreakMode = UILineBreakModeWordWrap;
                  label.highlightedTextColor = [UIColor whiteColor];
                  label.numberOfLines = 0;
                  label.opaque = NO; // 選中Opaque表示視圖后面的任何內容都不應該繪制
                  label.backgroundColor = [UIColor clearColor];
                  [cell.contentView addSubview:label];
                  [label release];
              }
              UILabel *label = (UILabel *)[cell viewWithTag:1];
              NSString *text;
              text = [textArray objectAtIndex:indexPath.row];
              CGRect cellFrame = [cell frame];
              cellFrame.origin = CGPointMake(0, 0);
              label.text = text;
              CGRect rect = CGRectInset(cellFrame, 2, 2);
              label.frame = rect;
              [label sizeToFit];
              if (label.frame.size.height > 46) {
                  cellFrame.size.height = 50 + label.frame.size.height - 46;
              }
              else {
                  cellFrame.size.height = 50;
              }
              [cell setFrame:cellFrame];
              return cell;
          }
          - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
              UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
              return cell.frame.size.height;
          }
          posted on 2011-07-22 16:27 棋劍小秋 閱讀(209) 評論(0)  編輯  收藏 所屬分類: iPhone
          主站蜘蛛池模板: 花莲县| 新丰县| 利川市| 江陵县| 民县| 松江区| 张掖市| 桂林市| 基隆市| 龙海市| 临澧县| 措美县| 达孜县| 大厂| 普陀区| 屯留县| 西安市| 康平县| 五大连池市| 通州市| 曲沃县| 平谷区| 赤城县| 麟游县| 湘潭县| 扎鲁特旗| 三河市| 佛冈县| 集贤县| 山丹县| 邓州市| 杨浦区| 罗定市| 灵台县| 上杭县| 加查县| 宁城县| 宿迁市| 丰顺县| 汉阴县| 永德县|