Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个小问题...如何搜索导航栏的子视图?如何获取导航栏的子视图?
如果我正确理解了您的问题,那么您可以这样做:
for (UIView *temp in self.navigationController.navigationBar.subviews) { if ([temp isKindOfClass:[UIButton class]]) { NSLog(@"is button !"); UIButton *tempButton = (UIButton *)temp ; } else if ([temp isKindOfClass:[UILabel class]]) { } }
您不必搜索导航栏的子视图来更改标题标签的属性。您可以访问 viewcontroller 的 navigationItem 的 titleView 并将其设置为您使用自定义字体创建的标签。
这方面的例子可以在这个答案中看到。
另一种解决方案是使用导航控制器 UINavigationBar 的 titleTextAttributes 属性来设置标题的字体。更多信息在这里。此解决方案可能是最正确的方法,但它仅适用于 iOS 5 及更高版本。