2013-10-15 27 views

回答

0

如果您想製作相同類型的視圖(如上圖所示),請在該部分的頁腳中放置一個標籤,使標籤的背景透明並根據您的選擇設置其框架,並添加文本你想放在那裏。讓我給你一個可能幫助你的代碼片段。

UILabel *tableFooter = [[UILabel alloc] initWithFrame:footerRect]; 
tableFooter.textColor = // add color of your choice 
tableFooter.backgroundColor = // add color of your choice 
tableFooter.opaque = YES; 
tableFooter.font = [UIFont boldSystemFontOfSize:15]; 
tableFooter.text = @" add text of your choice"; 
self.theTable.tableFooterView = tableFooter; 
[tableFooter release]; 

把上面的代碼中此方法:

- (UIView *) tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section 
0

退房此委託方法:

- (NSString *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section 
2

這是寫在頁眉和UITableView中的頁腳。因此,請自定義表格中的部分的headerView和footerView。

使用以下方法:

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section 

希望它可以幫助你。

0

你下面的方法它的工作對我來說我的應用程序:

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    /* ios 7 Change */ 
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) 
    { 
     self.edgesForExtendedLayout = UIRectEdgeNone; 
     self.edgesForExtendedLayout = UIRectEdgeNone; 
     self.tableview.separatorInset = UIEdgeInsetsZero; 
     [self.tableview setSeparatorStyle:UITableViewCellSeparatorStyleNone]; 
    } 
} 

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 
    NSString *header; 

    float start = 10.0, startLabel = 10.0; 

    if ([UICommonUtils isiPad]) 
    { 
     startLabel = 50.0; 
    } else { 
     startLabel = 10.0; 
    } 

    CGRect rectFrame = [UIScreen mainScreen].applicationFrame; 


     UIView* customView = [[[UIView alloc] 
          initWithFrame:CGRectMake(start, 0.0, rectFrame.size.width - 20.0, 80.0)] 
          autorelease]; 
    /* 
    customView.backgroundColor = 
    [UIColor colorWithRed:.6 green:.6 blue:1 alpha:.9]; 
    */ 
     UILabel * headerLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease]; 
     //UILabel * headerLabel = [[[UILabel alloc] initWithStyle:UITableViewCellStyleDefault] autorelease]; 
     headerLabel.backgroundColor = [UIColor clearColor]; 
     headerLabel.opaque = NO; 
     //headerLabel.textColor = [UIColor darkGrayColor]; 
     headerLabel.textColor = [UIColor colorWithRed:0.298039 green:0.337255 blue:0.423529 alpha:1]; 
     headerLabel.shadowColor = [UIColor whiteColor]; 
     headerLabel.shadowOffset = CGSizeMake(0.0, 1.0); 
     headerLabel.font = [UIFont boldSystemFontOfSize:17.0]; 
     //headerLabel.frame = CGRectMake(startLabel, 0, rectFrame.size.width - 60.0, 20.0); 
     headerLabel.frame = CGRectMake(startLabel, 10, rectFrame.size.width - 35.0, 20.0); 
     headerLabel.textAlignment = UITextAlignmentLeft; 
     headerLabel.lineBreakMode = UILineBreakModeWordWrap; 
     headerLabel.text = header; 
     headerLabel.baselineAdjustment = UIBaselineAdjustmentAlignCenters; 

     UILabel * footerLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease]; 
     //UILabel *footerLabel = [[[UILabel alloc] initWithStyle:UITableViewCellStyleDefault] autorelease]; 
     footerLabel.backgroundColor = [UIColor clearColor]; 
     footerLabel.opaque = NO; 
     //footerLabel.textColor = [UIColor darkGrayColor]; 
     footerLabel.textColor = [UIColor colorWithRed:0.298039 green:0.337255 blue:0.423529 alpha:1]; 
     footerLabel.shadowColor = [UIColor whiteColor]; 
     footerLabel.shadowOffset = CGSizeMake(0.0, 1.0); 
     footerLabel.font = [UIFont systemFontOfSize:14.0]; 
     float height; 
     if ([UICommonUtils isiPad]) 
      height = 40.0; 
     else 
      height = 50.0; 
     footerLabel.frame = CGRectMake(startLabel, 20, rectFrame.size.width - 60.0, height); 
     footerLabel.textAlignment = UITextAlignmentLeft; 
     footerLabel.lineBreakMode = UILineBreakModeWordWrap; 
     footerLabel.baselineAdjustment = UIBaselineAdjustmentNone; 
     footerLabel.numberOfLines = 0; 
     footerLabel.text = detail; 

     [customView addSubview:headerLabel]; 
     [customView addSubview:footerLabel]; 

     return customView; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 
{ 
    if ([UICommonUtils isiPad]) return 60.0; 
     else return 70.0; 

} 

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section 
{ 
    return 0; 
} 

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection: (NSInteger)section 
{ 
return kProductHeader; 
} 

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

/* ios 7 Change */ 
    if ([cell respondsToSelector:@selector(tintColor)]) { 
     if (tableView == self.tableview) { 
      CGFloat cornerRadius = 5.f; 
      cell.backgroundColor = UIColor.clearColor; 
      CAShapeLayer *layer = [[CAShapeLayer alloc] init]; 
      CGMutablePathRef pathRef = CGPathCreateMutable(); 
      CGRect bounds = CGRectInset(cell.bounds, 10, 0); 
      BOOL addLine = NO; 
      if (indexPath.row == 0 && indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) { 
       CGPathAddRoundedRect(pathRef, nil, bounds, cornerRadius, cornerRadius); 
      } else if (indexPath.row == 0) { 
       CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds)); 
       CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius); 
       CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius); 
       CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds)); 
       addLine = YES; 
      } else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) { 
       CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds)); 
       CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius); 
       CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius); 
       CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds)); 
      } else { 
       CGPathAddRect(pathRef, nil, bounds); 
       addLine = YES; 
      } 
      layer.path = pathRef; 
      CFRelease(pathRef); 
      layer.fillColor = [UIColor colorWithWhite:1.f alpha:0.8f].CGColor; 

      if (addLine == YES) { 
       CALayer *lineLayer = [[CALayer alloc] init]; 
       CGFloat lineHeight = (1.f/[UIScreen mainScreen].scale); 
       lineLayer.frame = CGRectMake(CGRectGetMinX(bounds)+10, bounds.size.height-lineHeight, bounds.size.width-10, lineHeight); 
       lineLayer.backgroundColor = tableView.separatorColor.CGColor; 
       [layer addSublayer:lineLayer]; 
      } 
      UIView *testView = [[UIView alloc] initWithFrame:bounds]; 
      [testView.layer insertSublayer:layer atIndex:0]; 
      testView.backgroundColor = UIColor.clearColor; 
      cell.backgroundView = testView; 
     } 
    } 
}