一般的我们都是通过自定义视图来设置导航条的title颜色和字体的 UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 40)]; titleLabel.text = @"详情"; titleLabel.textColor = [UIColor whiteColor]; titleLabel.textAlignment = NSTextAlignmentCenter; self.navigationItem.titleView = titleLabel; 但是iOS6之后有了新的方法可以直解设置title的字体和颜色 [self.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, [UIFont systemFontOfSize:20], NSFontAttributeName, nil]];
时间: 2024-10-08 18:52:20