我希望导航栏中的标题自动缩小,以便适合整个标题。我尝试了以下代码,但标题仍然被切断。
- (void) viewDidLoad {
UILabel* titleLabel = [[UILabel alloc] init];
titleLabel.font = [UIFont boldSystemFontOfSize:16.0];
titleLabel.text = @"abcdefghijklmnopqrstuvwxyz";
if ([titleLabel respondsToSelector:@selector(setMinimumScaleFactor:)]) {
titleLabel.minimumScaleFactor = 0.1;
} else {
titleLabel.minimumFontSize = 1.0;
}
[titleLabel sizeToFit];
self.navigationItem.titleView = titleLabel;
}