如何更改表格 View 部分中文本的位置?我使用 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 中垂直居中文本?
谢谢
最佳答案
尝试
[yourLabel setNumberOfLines:0];
[yourLabel sizeToFit];
[yourLabel setContentMode:UIViewContentModeCenter];
关于iphone - 在表格 View 部分标题中垂直居中 UILabel 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14483250/