[英]Adjust font size in Navigation Title
有沒有辦法讓導航欄的標題字體調整寬度?
與[UILabel setAdjustsFontSizeToFitWidth:YES]
行為相同。
我正在嘗試設置NavigationBar的外觀,但到目前為止還沒有成功。
嘗試做類似的事情:
self.navigationItem.titleView = titleLabel;
其中titleLabel
是您已初始化和自定義的自定義UILabel
。
例如,查看這個Fontful代碼 。
使用標准標題項無法做到這一點。 您仍然可以將自定義UILabel
添加到導航欄並處理標題更改。
您無法更改標題的字體。
相反,試試這個..
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];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.