gpt4 book ai didi

ios - 如何使 UITableView 的部分标题居中

转载 作者:IT王子 更新时间:2023-10-29 07:46:14 26 4
gpt4 key购买 nike

我想将表头置于 tableview 的中心,但是我有 2 个问题。首先我没有正确的高度,其次 UILabel 看起来不像默认标题 - 字体/字体大小/颜色等......是否有更好的居中方式,和/或有没有办法制作它看起来像默认 header 。

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger) section
{
//section text as a label
UILabel *lbl = [[UILabel alloc] init];
lbl.textAlignment = UITextAlignmentCenter;

lbl.text = @"Header";
[lbl setBackgroundColor:[UIColor clearColor]];

return lbl;
}

最佳答案

这应该可以解决您的问题。在 xcode 6/ios8 中测试

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
[[UILabel appearanceWhenContainedIn:[UITableViewHeaderFooterView class], nil] setTextAlignment:NSTextAlignmentCenter];
return [sectionTitles objectAtIndex:section];
}

关于ios - 如何使 UITableView 的部分标题居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4875391/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com