我有一些代码允许我自定义视图的导航栏标题,以允许缩小/截断长标题。该代码几乎在任何地方都可以正常工作,但是当它在 UITableViewController 中使用时,标题永远不会出现。
有问题的代码是:
- (void)viewDidLoad
{
[super viewDidLoad];
//Nav bar title for truncating longer titles
CGRect frame = CGRectMake(0, 0, 400, 44);
UILabel *label = [[UILabel alloc] initWithFrame:frame];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:20.0];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.adjustsFontSizeToFitWidth = YES;
label.minimumFontSize = 10.0f;
label.lineBreakMode = UILineBreakModeTailTruncation;
label.text = @"This is a really long title. It will shrink and eventually get truncated correctly.";
self.navigationItem.titleView = label;
}
我整理了一个说明问题的小型演示项目。 https://sites.google.com/site/coffeestainit/files/NavTitleError.zip