有没有方法实现导航标题的字体根据宽度调整?
比如[UILabel setAdjustsFontSizeToFitWidth:YES]
试过很多方法都没实现,请好心人帮忙,谢谢。
自定义UINavigationItem的titleView
在titleView中创建一个UILabel ,设置UILabel的相关属性再试。
UILabel *lbl=[[UILabel alloc] initWithFrame:....];
[lbl setAdjustsFontSizeToFitWidth:YES];
...
self.navigationItem.titleView=lbl;
self.title = @"My title is this.";
CGRect frame = CGRectMake(0, 0, [self.title sizeWithFont:[UIFont boldSystemFontOfSize:20.0]].width, 44);
UILabel *label = [[UILabel alloc] initWithFrame:frame];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:17.0];
label.textAlignment = UITextAlignmentCenter;
self.navigationItem.titleView = label;
label.text = self.title;
[label release];