本文主要是介绍IOS开发自定义UITableView的Header,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
- - (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;
- }
这篇关于IOS开发自定义UITableView的Header的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!