UINavigationBar:旋转后更改标题大小

时间:2012-05-29 21:27:56

标签: iphone ios5

我在AppDelegate didFinishLaunchingWithOptions中使用以下代码更改了UINavigationBar标题的字体:

[[UINavigationBar appearance] setTitleTextAttributes:
  [NSDictionary dictionaryWithObjectsAndKeys: [UIFont fontWithName:@"Arial-BoldMT" size:24.0], UITextAttributeFont, nil]];

在肖像中没关系,但在横向上字体大小太大。 旋转设备后是否可以更改字体大小?

我想我可以使用自定义titleView来解决这个问题,但我想知道是否还有其他选项(没有将大小设置为纵向中的较小数字/通常:))?

我正在为iOS 5开发。

1 个答案:

答案 0 :(得分:1)

使用可见视图控制器中的这两种方法之一设置属性,根据设备当前的方向修改代码。视图控制器需要指向UINavigationController变量的指针。

在视图旋转之前调用的方法: - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

视图旋转后立即调用的方法:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

有关ViewController方法的更多信息,请访问:

http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIViewController_Class/Reference/Reference.html

我认为最简单的方法是使用if语句将title属性设置为一种样式(如果设备是verticle),否则设置为另一种样式,因为设备是水平的。

相关问题