【发布时间】:2013-01-23 15:31:57
【问题描述】:
如何更改表格视图部分中文本的位置?我使用 viewForHeaderInSection:Section 并在那里创建这样的东西:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 30)];
label.backgroundColor = [UIColor blackColor];
label.textColor = [UIColor whiteColor];
label.font = [UIFont fontWithName:@"Gotham-Bold" size:17.0f];
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.comlpetedFetchedResultsController sections] objectAtIndex:section];
label.text = [@" " stringByAppendingString:[sectionInfo name]];
return label;
}
UILabel 框架中的参数大小无关紧要,我总是得到相同的结果:
如何在 UILabel 中垂直居中文本? 谢谢
【问题讨论】:
-
你可以看到文字在黑色UILabel的顶部,我想让它居中(现在稍微往下一点)
-
您是否尝试使用 label 将标签中的文本居中。 textAlignment =UITextAlignmentCenter
-
你尝试改变 y 吗? UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 3, 300, 30)];
-
@Simone 是的,我试过了,没用。
-
好的,如果你创建了一个 UIView,并把 UILabel 放在它上面并改变了 y 并返回 UIView 而不是 UILabel?
标签: iphone ios uitableview