iphone - 在表格 View 部分标题中垂直居中 UILabel 文本

标签 iphone ios uitableview

如何更改表格 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 框架中的参数大小无关紧要,我总是得到相同的结果:

enter image description here

如何在 UILabel 中垂直居中文本?
谢谢

最佳答案

尝试

[yourLabel setNumberOfLines:0];
[yourLabel sizeToFit];
[yourLabel setContentMode:UIViewContentModeCenter];

关于iphone - 在表格 View 部分标题中垂直居中 UILabel 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14483250/

相关文章:

iphone - 使 ImageView 出现在 Safari Top Sites 中

objective-c - 用户接受后,iRate 会自动停止征求评论吗?

ios - ReactJS 网站在 IOS 中默认打开为桌面版,请求时更改为移动版桌面版

ios - 在另一个 ViewController 中从 'UIImagePickerController' 更改 UIImageView 图像会因 'fatal error: unexpectedly found nil' 而崩溃

uitableview - iOS Swift - 使用搜索栏和搜索显示过滤具有自定义单元格的 UITableView 的内容

ios - 获取某些单元格的快照不起作用

ios - 动态静态 TableView

iphone - Testflight 无法识别新设备

iphone - Points对UIImage的透视校正

c# - 有一种方法可以按位置从服务器端向设备发送推送吗?