我想从中间截断视图标题。
代码: -
self.title = [NSString stringWithFormat:NSLocalizedString(@"SearchResultWithCount", nil), self.searchString,[self.sortedFileList count]];
输出: - SearchResultWithCount(61 ...
但希望标题类似于: - SearchRe ... thCount(612)。
请帮帮我。
答案 0 :(得分:1)
我遇到了同样的问题,请尝试以下代码:
CGSize size=[[UIScreen mainScreen] bounds ].size;
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(size.width/2-120, 5, 200, 44)];
titleLabel.text = your_title_text;
titleLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
[self.navigationItem setTitleView:titleLabel];
[self.navigationController.navigationBar.topItem setTitleView:titleLabel];
答案 1 :(得分:0)
Swift 4
let titleLabel = UILabel()
titleLabel.text = self.searchString
titleLabel.lineBreakMode = .byTruncatingMiddle
navigationItem.titleView = titleLabel