我正在努力设计UIView Header的样式,我正在使用IOS7故事板和自定义单元格-每个单元格都有自己的类-
我想用白色文本实现不透明的灰色背景-Helvetica Neue Medium字体大小16-初始标题隐藏在HeightForHeaderInSection方法中-到目前为止我已经-
- (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"
}
}