IOS - 静态 UITableViewController 中的样式部分标题 - IOS7.



是否可以在静态UITableViewController中设置节标题背景/字体样式的样式? 我看不到任何故事板选项来执行此操作,并且由于表是静态的,因此表中的表方法已被禁用。M 文件 - 所以我也不确定如何以编程方式应用样式?

UITableViewDelegate 协议定义了一个方法 viewForHeaderInSection 方法,该方法可以在委托中实现以返回自定义标头视图(也适用于静态 UITableViews)。 例如:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    // you can get the title you statically defined in the storyboard
    NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
    // create and return a custom view
    UILabel *customLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 200.0f, 50.0f)];
    customLabel.text = sectionTitle;
    return customLabel;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    // return a custom height here if necessary
    return 50.0f;
}

最新更新