1

我想为 UINavigationItem 中出现的文本配置截断模式。

我遇到了几种配置字体大小的不同解决方案,但不确定如何使用 NSString 上存在的 UILineBreakModeHeadTruncation。

我如何能够配置字体大小:

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 120, 30)];
[label setFont:[UIFont boldSystemFontOfSize:16.0]];
[label setBackgroundColor:[UIColor clearColor]];
[label setTextColor:[UIColor whiteColor]];
[label setText:self.title];
[self.navigationController.navigationBar.topItem setTitleView:label];
[label release];

(基于这里的推荐

如果我在 loadView 或 viewDidLoad 中调用它,它似乎可以工作,但在该方法之外,在加载视图后,它似乎不起作用。不知道为什么。

4

1 回答 1

2

您尝试了什么,什么不起作用?你应该能够做到:

label.lineBreakMode = UILineBreakModeHeadTruncation;

或者换行到多行:

label.lineBreakMode = UILineBreakModeWordWrap;
label.numberOfLines = 0;
于 2010-11-30T01:05:28.207 回答