Custom back indicator image in iOS 7 not vertically centered

吃可爱长大的小学妹 提交于 2019-12-10 12:30:41

问题


I am using the following code to use a custom image for the back indicator in my iOS 7 app:

UIImage *temp = [[UIImage imageNamed:@"back-black-on-black-normal-2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[[UINavigationBar appearance] setBackIndicatorImage:temp];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:temp];

The strange thing is, if I use an image that is 22px high (way too small for what we want, by the way), it centers vertically within in the nav bar just fine. Once I start to make it a more reasonable size, however, it gets way off vertically (here it's 44px high, still too small for us but not centering at all, as you can see):

Any help or suggestions greatly appreciated. Thanks.


回答1:


Check button image, is there any unwanted bottom space?




回答2:


Try with the bellow code.

   UIImage *temp = [UIImage imageNamed:@"BackBarButton.png"];

   self.navigationController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:temp style:UIBarButtonItemStylePlain target:self action:@selector(back_Clicked:)];


 -(void)back_Clicked:(UIBarButtonItem*)loBtn
 {
    [self.navigationController popViewControllerAnimated:YES];
 }


来源:https://stackoverflow.com/questions/21684661/custom-back-indicator-image-in-ios-7-not-vertically-centered

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!