作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
从一个 UITableView 中,我使用以下代码将另一个带有另一个 UITableView 的 View Controller 推送到堆栈上:
// allocate and create instance of categories view controller
TJKCategoriesViewController *categoriesViewController = [[TJKCategoriesViewController alloc] init];
// push it onto the top of the navigation controller's stack
[self.navigationController pushViewController:categoriesViewController animated:YES];
当我在 TJKCategoriesViewContoller 的 viewDidLoad 方法中时,我正在使用以下代码更改标题:
self.title = @"Categories";
这很好用。但是,“类别”标题显示为黑色,我希望它是不同的颜色。我试过像 tintColor 这样的东西,但是 self.title 没有这个属性。
有人有什么建议吗?
谢谢,格伦
最佳答案
您可以创建一个 UILabel 并将其设置为 UINavigationItem 的 titleView。请参阅苹果文档:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationItem_Class/#//apple_ref/occ/instp/UINavigationItem/titleView
部分代码:
- (void)setMyTitle:(NSString *)title
{
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.navigationController.view.bounds.size.width - 100, 44)];
titleLabel.text = title;
titleLabel.font = [UIFont systemFontOfSize:16];
titleLabel.textColor = ...
...
self.navigationItem.titleView = titleLabel;
}
关于ios - 如何更改压入堆栈的 View Controller 的标题颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35421286/
我是一名优秀的程序员,十分优秀!