如何设置tableview的headerview
2016-01-11
展开全部
(UIView *)tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section{
UIView *v_headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 23)];//创建一个视图(v_headerView)
UIImageView *v_headerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 23)];//创建一个UIimageView(v_headerImageView)
v_headerImageView.image = [UIImage imageNamed:@"ip_top
bar.png"];//给v_headerImageView设置图片
[v_headerView addSubview:v_headerImageView];//将v_headerImageView添加到创建的视图(v_headerView)中
[v_headerImageView release];//释放v_headerImageView所占用的资源
UILabel *v_headerLab = [[UILabel alloc] initWithFrame:CGRectMake(10, 1, 100, 19)];//创建一个UILable(v_headerLab)用来显示标题
v_headerLab.backgroundColor = [UIColor clearColor];//设置v_headerLab的背景颜色
v_headerLab.textColor = [UIColor grayColor];//设置v_headerLab的字体颜色
v_headerLab.font = [UIFont fontWithName:@"Arial" size:13];//设置v_headerLab的字体样式和大小
v_headerLab.shadowColor = [UIColor whiteColor];//设置v_headerLab的字体的投影
[v_headerLab setShadowOffset:CGSizeMake(0, 1)];//设置v_headerLab的字体投影的位置
//设置每组的的标题
if (section == 0) {
v_headerLab.text = @"拍品导航";
}
if (section == 1) {
v_headerLab.text = @"专场特卖";
}
[v_headerView addSubview:v_headerLab];//将标题v_headerLab添加到创建的视图(v_headerView)中
[v_headerLab release];//释放v_headerLab所占用的资源
return v_headerView;//将视图(v_headerView)返回
viewForHeaderInSection:(NSInteger)section{
UIView *v_headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 23)];//创建一个视图(v_headerView)
UIImageView *v_headerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 23)];//创建一个UIimageView(v_headerImageView)
v_headerImageView.image = [UIImage imageNamed:@"ip_top
bar.png"];//给v_headerImageView设置图片
[v_headerView addSubview:v_headerImageView];//将v_headerImageView添加到创建的视图(v_headerView)中
[v_headerImageView release];//释放v_headerImageView所占用的资源
UILabel *v_headerLab = [[UILabel alloc] initWithFrame:CGRectMake(10, 1, 100, 19)];//创建一个UILable(v_headerLab)用来显示标题
v_headerLab.backgroundColor = [UIColor clearColor];//设置v_headerLab的背景颜色
v_headerLab.textColor = [UIColor grayColor];//设置v_headerLab的字体颜色
v_headerLab.font = [UIFont fontWithName:@"Arial" size:13];//设置v_headerLab的字体样式和大小
v_headerLab.shadowColor = [UIColor whiteColor];//设置v_headerLab的字体的投影
[v_headerLab setShadowOffset:CGSizeMake(0, 1)];//设置v_headerLab的字体投影的位置
//设置每组的的标题
if (section == 0) {
v_headerLab.text = @"拍品导航";
}
if (section == 1) {
v_headerLab.text = @"专场特卖";
}
[v_headerView addSubview:v_headerLab];//将标题v_headerLab添加到创建的视图(v_headerView)中
[v_headerLab release];//释放v_headerLab所占用的资源
return v_headerView;//将视图(v_headerView)返回
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询