- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试更改我的一个 View Controller 的字体大小,因为它适合更多文本,因此需要比我的其他 View 更小的字体大小。我在 didFinishLaunchingWithOptions 期间在 appdelegate 中设置导航栏属性,然后在 viewDidLoad 期间为我的相关 View Controller 设置字体。但是,当我后退或前进屏幕时,我对导航栏所做的更改将被保留,即较小的字体。有没有解决的办法?例如在退出 View 时将字体设置回正常?
Cliffsnotes:尝试只在一个 View Controller 中设置字体,但一旦我设置它,它就会应用于所有 View Controller 。
代码如下:
在 AppDelegate 中:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor clearColor],
UITextAttributeTextColor,
[UIColor whiteColor],
UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
UITextAttributeTextShadowOffset,
[UIFont fontWithName:@"QuicksandBold-Regular" size:24.0],
UITextAttributeFont,
nil]];
在 View Controller viewDidLoad中:
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor clearColor],
UITextAttributeTextColor,
[UIColor whiteColor],
UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
UITextAttributeTextShadowOffset,
[UIFont fontWithName:@"QuicksandBold-Regular" size:18.0],
UITextAttributeFont,
nil]];
最佳答案
导航栏由导航 Controller 中的所有 View Controller 共享。因此,一旦更改导航栏,同一导航堆栈中的所有 View Controller 都会受到影响。一种选择是为这个 View Controller 设置自定义 titleView。
self.navigationItem.titleView = ... // some UILabel with the desired formatting
这样,只有一个 View Controller 显示自定义标题。
另一种选择是在 View Controller 的 viewWillAppear 方法中更改导航栏的外观,然后在 View Controller 的 viewWillDisappear 方法中重置它。但是这种方法可能不像使用自定义 titleView 那样顺利。
关于ios - 如何仅为一个 View Controller 设置导航栏的 titletext 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12809024/
我在我的 android 游戏中使用 ScoreNinja(高分管理器),我想使用文档中提到的子板功能。 但是当我这样做的时候: mScoreNinjaAdapter.show(score, "Tes
有没有办法切换 title 的属性值? 好像文本标题是 在 我想用下面给出的代码切换它的标题文本和它的类: $('.postoption').click(function(){ $(thi
我正在尝试更改我的一个 View Controller 的字体大小,因为它适合更多文本,因此需要比我的其他 View 更小的字体大小。我在 didFinishLaunchingWithOptions
我在“applicationDidFinishLaunching”中使用外观代理将 UIBarButtonItem 和 UINavigationBar titleTextAttributes 的外观更
我是一名优秀的程序员,十分优秀!