现在的位置: 首页 > 综合 > 正文

修改UITableView section header title的样式

2018年07月14日 ⁄ 综合 ⁄ 共 958字 ⁄ 字号 评论关闭

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section; 
 
// fixed font style. use custom view (UILabel) if you want something different

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
	// create the parent view that will hold header Label
	UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 300.0, 20.0)];
	
	// create the button object
	UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
	headerLabel.backgroundColor = [UIColor clearColor];
	headerLabel.opaque = NO;
	headerLabel.textColor = [UIColor colorWithRed:(54.0 / 255.0) green:(100.0 / 255.0) blue:(139.0 / 255.0) alpha:1.0];
	headerLabel.highlightedTextColor = [UIColor blackColor];
	headerLabel.font = [UIFont boldSystemFontOfSize:15];
	headerLabel.frame = CGRectMake(17.0, 0.0, 300.0, 20.0);
	headerLabel.text = @"title for header";
	[customView addSubview:headerLabel];
    
	return customView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 30;
}

【上篇】
【下篇】

抱歉!评论已关闭.