Ios UITableView标题样式-字体颜色/背景/字体大小
我正在努力设计UIView标题的样式,我正在使用IOS7情节提要和自定义单元格-每个单元格都有自己的类- 我希望实现一个不透明的灰色背景和白色文本-Helvetica Neue中等字体大小16-初始标题隐藏在HeightForHeaderInSection方法中-到目前为止我已经-Ios UITableView标题样式-字体颜色/背景/字体大小,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我正在努力设计UIView标题的样式,我正在使用IOS7情节提要和自定义单元格-每个单元格都有自己的类- 我希望实现一个不透明的灰色背景和白色文本-Helvetica Neue中等字体大小16-初始标题隐藏在HeightForHeaderInSection方法中-到目前为止我已经- - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *hea
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
if (section == 0)
[headerView setBackgroundColor:[UIColor clearColor]];
else
[headerView setBackgroundColor:[UIColor colorWithRed:156.0f/255.0f green:156.0f/255.0f blue:156.0f/255.0f alpha:0.75f]];
[headerView setTintColor:[UIColor whiteColor]];
return headerView;
}
更新我的标题文本取自此方法-
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection: (NSInteger)section
{
if(section == 1)
{
return @"Offers";
}
else if(section == 2)
{
return @"Workouts";
}
else
{
return @"Weights";
}
}
您可以通过以下方式在
viewForHeaderInSection
中指定每个标题部分的标题:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
UILabel *labelHeader = [[UILabel alloc] initWithFrame:CGRectMake (0,0,320,30);
labelHeader.font = [UIFont ...]
labelHeader.textColor = [UIColor whiteColor];
[headerView addSubview:labelHeader];
if (section == 0)
[headerView setBackgroundColor:[UIColor clearColor]];
else if (section == 1) {
[headerView setBackgroundColor:[UIColor colorWithRed:156.0f/255.0f green:156.0f/255.0f blue:156.0f/255.0f alpha:0.75f]];
labelHeader.text = @"Offers"
}
else if (section == 2) {
[headerView setBackgroundColor:[UIColor colorWithRed:156.0f/255.0f green:156.0f/255.0f blue:156.0f/255.0f alpha:0.75f]];
labelHeader.text = @"Workouts"
}
else {
[headerView setBackgroundColor:[UIColor colorWithRed:156.0f/255.0f green:156.0f/255.0f blue:156.0f/255.0f alpha:0.75f]];
labelHeader.text = @"Weights"
}
}
如何将文本添加到headerView?也许您应该将文本添加到
headerView
?抱歉,我想我不明白这个问题。抱歉@llario-不,在实现上述方法之前,文本就在那里-它从数组中拉出,并在我的titleForHeaderSection方法中过滤-一旦我应用上述样式,它就不可见。使用此代码,如何传递文本?抱歉,我无法理解此代码添加了上面的titleforheader方法-干杯