博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
自定义UITableView的Header
阅读量:4108 次
发布时间:2019-05-25

本文共 1220 字,大约阅读时间需要 4 分钟。

转自
Java代码  
  1. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section  
  2. {  
  3.       
  4.       
  5.     // create the parent view that will hold header Label  
  6.     UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0.00.032020.0)];  
  7.       
  8.     UIImageView *bg = [[UIImageView alloc]initWithFrame:customView.frame];  
  9.      
  10.     bg.image = [UIImage imageNamed:@"carTypeCellTitleBg1.png"];  
  11.     
  12.       
  13.     [customView addSubview:bg];  
  14.       
  15.     // create the button object  
  16.     UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];  
  17.       
  18.     headerLabel.backgroundColor = [UIColor clearColor];  
  19.       
  20.     headerLabel.opaque = NO;  
  21.     headerLabel.textColor = [UIColor colorWithRed:242.0/255.0f green:161.0/255.0f blue:4.0/255.0 alpha:1.0];  
  22.       
  23.     //  headerLabel.highlightedTextColor = [UIColor whiteColor];  
  24.       
  25.     headerLabel.font = [UIFont italicSystemFontOfSize:15];  
  26.     headerLabel.frame = customView.frame;  
  27.       
  28.     // If you want to align the header text as centered  
  29.     // headerLabel.frame = CGRectMake(150.0, 0.0, 300.0, 44.0);  
  30.       
  31.     //  headerLabel.text = <Put here whatever you want to display> // i.e. array element  
  32.       
  33.       
  34.     headerLabel.text = @"title";  
  35.       
  36.     [customView addSubview:headerLabel];  
  37.       
  38.     return customView;  
  39.       
  40. }  
  41.   
  42. - (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section  
  43. {  
  44.     return 21.0;  
  45. }  

转载地址:http://guvsi.baihongyu.com/

你可能感兴趣的文章
强大的Core Image(教你做自己的美图秀秀)
查看>>
iOS6下UITextField垂直居中问题
查看>>
系统设置内添加应用设置Setting的实现
查看>>
在iOS端如何使用Charles用作http调试
查看>>
IOS下利用ziparchive解压缩zip文件
查看>>
IOS中如何Hook消息
查看>>
ios 通讯录 通过电话号码 查询姓名
查看>>
Sublime Text 2 实用快捷键[Mac OS X]
查看>>
CATransform3DMakeRotation 旋转,翻转
查看>>
NSDateFormatter NSDateComponents iphone 时间格式详解
查看>>
渐隐渐现效果代码
查看>>
iOS-ssh无密码登入设置
查看>>
Vi使用指南
查看>>
旋转动画 uiview animation rotate
查看>>
[iOS] iphone检测耳机插入/拔出
查看>>
IOS 定位服务
查看>>
IOS4+ 发短信
查看>>
RunLoop的原理和应用
查看>>
plist文件,Property List 文件
查看>>
iPhone在scrollview中双击定点放大的代码
查看>>