简体   繁体   中英

set image for navigation title is not properly working in landscape

I used this following code to set image for navigation title but when i checked it on landscape the image is coming out of navigation bar.I tried resizing but its not working.thanks

UIImageView *image=[[UIImageView alloc]initWithFrame:CGRectMake(0,0,45,45)] ;
    [image setImage:[UIImage imageNamed:@"titleimage.png"]];
    [self.navigationController.navigationBar.topItem setTitleView:image];

In landscape the navigation bar is 32 points high rather than 44. So, in both orientations your image view is too big really. But in landscape you should be replacing the image view with a new instance with a smaller frame height.

Resize or change the UIImageView size when device going to change orientation, implement this delegate method

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{
   //You can replace image view with new, or you can set the frame of already existing image view in here. height should be 32 for iPhone
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM