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;
}
复制代码
{
// 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;
}
复制代码
相关文章推荐
- UIViewController中各方法调用顺序及功能详解
- request取参数值问题
- UIPickerView常用属性和方法总结
- UITableviewCell使用以及自定义高度
- iOS UITextField 使用全解
- Build Your Own Images
- Android的线程使用来更新UI----Thread、Handler、Looper、TimerTask等
- request用getQueryString()获取参数中文转码问题
- easy ui diglog 点击关闭,触发事件
- pcDuino无显示器刷机与使用
- bat实现检测fluent当前文件夹最新文件
- UIImage裁剪图片指定frame
- pcDuino 刷系统-LiveSuit
- pcDuino汉化方法
- iOS—UIScrollView简单介绍
- 在未来UI设计将短信化
- poj1947Rebuilding Roads【树型dp 01背包】
- <LeetCode OJ> Longest Increasing Subsequence【300】
- easyui datagrid checkbox初始化某几行disabled时,点击全选还是可以选择 解决办法
- js中的循环流程的控制return false,return true,break,continue