gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 21:32:18 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com