iOS開發之設定導航欄標題的字型大小和顏色
阿新 • • 發佈:2019-01-01
方法一:自定義檢視。
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 44)]; titleLabel.backgroundColor = [UIColor grayColor]; titleLabel.font = [UIFont boldSystemFontOfSize:20]; titleLabel.textColor = [UIColor blueColor]; titleLabel.textAlignment = NSTextAlignmentCenter; titleLabel.text = @"導航欄標題"; self.navigationItem.titleView = titleLabel;
方法二:在預設顯示的標題中直接修改文字的大小和顏色。
self.navigationItem.title = @"導航欄標題";
[self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor blueColor]}];