iPhone Title and Subtitle in Navigation Bar

前端 未结 2 866
灰色年华
灰色年华 2020-12-23 18:39

In my application, I\'d like to have the navigation bar display a title and subtitle.

To that extent, I added the following code to my view controller:



        
2条回答
  •  一个人的身影
    2020-12-23 19:02

    Make the titleView and subtitleView labels into properties of the view controller, so that you can access them from any method. Then, on rotation of the view controller, resize the labels:

    - (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
        [self adjustLabelsForOrientation:toInterfaceOrientation];
    }
    
    - (void) adjustLabelsForOrientation:(UIInterfaceOrientation)orientation {
        if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
            titleView.font = [UIFont boldSystemFontOfSize:16];
            subtitleView.font = [UIFont boldSystemFontOfSize:11];
        }
        else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
            titleView.font = [UIFont boldSystemFontOfSize:20];
            subtitleView.font = [UIFont boldSystemFontOfSize:13];
        }
    }
    

提交回复
热议问题