ios - 如何更改压入堆栈的 View Controller 的标题颜色?

标签 ios objective-c uitableview uiviewcontroller uinavigationcontroller

从一个 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/

相关文章:

ios - 提取 JSON 并将其保存在 NSMutableArray 中

ipad - 如何在 iPad 的 View Controller 中创建多个表格 View ?

c# - 如何从 TableView 传递数据? (Xamarin.iOS)

ios - iOS 中带有进度报告的可取消异步操作集

ios - swift 类和 Objective -c Viewcontrollers 之间的通知中心网络

ios - KeychainItemWrapper 迁移数据抛出错误

ios - 使用 Swift 获取 UITableViewCell 中 UITextField 的 indexPath

objective-c - 两个对象可以是彼此的代表吗......?

ios - NSMutableOrderedSet 到 NSMutableArray

objective-c - 将 Brother PJ-673 SDK (Objective-C) 绑定(bind)到 MonoTouch