您的位置:首页 > 产品设计 > UI/UE

IOS开发自定义UITableView的Header

2015-12-29 10:51 197 查看
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

  {

  // create the parent view that will hold header Label

  UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320, 20.0)];

  UIImageView *bg = [[UIImageView alloc]initWithFrame:customView.frame];

  bg.image = [UIImage imageNamed:@"carTypeCellTitleBg1.png"];

  [customView addSubview:bg];

  // create the button object

  UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];

  headerLabel.backgroundColor = [UIColor clearColor];

  headerLabel.opaque = NO;

  headerLabel.textColor = [UIColor colorWithRed:242.0/255.0f green:161.0/255.0f blue:4.0/255.0 alpha:1.0];

  // headerLabel.highlightedTextColor = [UIColor whiteColor];

  headerLabel.font = [UIFont italicSystemFontOfSize:15];

  headerLabel.frame = customView.frame;

  // If you want to align the header text as centered

  // headerLabel.frame = CGRectMake(150.0, 0.0, 300.0, 44.0);

  // headerLabel.text = <:Put display to want you whatever here>// i.e. array element

  headerLabel.text = @"title";

  [customView addSubview:headerLabel];

  return customView;

  }

  - (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

  {

  return 21.0;

  }

复制代码
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: