iOS中設置導航欄標題的字體顏色和大小,有須要的朋友能夠參考下。php
在平時開發項目的時候,不免會遇到修改導航欄字體大小和顏色的需求,通常使用自定義視圖的方法,其實還存在一種方法。app
方法一:(自定義視圖的方法,通常人也會採用這樣的方式)字體
就是在導航向上添加一個titleView,可使用一個label,再設置label的背景顏色透明,字體什麼的設置就很簡單了。ui
//自定義標題視圖url
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];spa
titleLabel.backgroundColor = [UIColor grayColor];orm
titleLabel.font = [UIFont boldSystemFontOfSize:20];開發
titleLabel.textColor = [UIColor greenColor];get
titleLabel.textAlignment = NSTextAlignmentCenter;it
titleLabel.text = @"新聞";
self.navigationItem.titleView = titleLabel;
方法二:(在默認顯示的標題中直接修改文件的大小和顏色也是能夠的)
[self.navigationController.navigationBar setTitleTextAttributes:
@{NSFontAttributeName:[UIFont systemFontOfSize:19],
NSForegroundColorAttributeName:[UIColor redColor]}];
方式二相對於方式一而言更加簡單方便