iOS 7:自定义后退指示图像位置 [英] iOS 7: Custom Back Indicator Image Position

查看:151
本文介绍了iOS 7:自定义后退指示图像位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法正确设置自定义后退指示图像。指标不居中!

I'm having trouble setting properly a custom back indicator image. The indicator is not centered!

这是一张图片:

我在中设置指标图像didFinishLaunchingWithOptions :方法...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

   UIImage *image = [UIImage imageNamed:@"Back"];
   [UINavigationBar appearance].backIndicatorImage = image;
   [UINavigationBar appearance].backIndicatorTransitionMaskImage = image;

   return YES;
}

我如何集中它?

ps我已经读过这个 iOS 7中的自定义后退指示符图像不是垂直居中的,但实际上它对我不起作用。

p.s I've already read this Custom back indicator image in iOS 7 not vertically centered, but actually it didn't work for me.

推荐答案

之所以发生这种情况,是因为您只是在UINavigationView中更改后退指示器的图像源,而不是框架。
请参阅创建UINavigationView时,后退指示器的框架设置为保持默认iOS 7后退按钮图像的大小。默认的后退按钮图像比你的大,这就是它看起来没有对齐的原因。

That happens because you are just changing the image source of the Back Indicator in your UINavigationView, and not the frame as well. See, when the UINavigationView is created, the Back Indicator's frame is set to hold the size of the default iOS 7 back button image. The default back button image is bigger than yours, and that's why it looks not aligned.

要解决这个问题,你必须重置后退指示器的框架以保持你的尺寸。图片。另一种选择是创建具有正确帧大小和图像的UIButton,并分配给UIBarButtonItem。然后,您可以使用您创建的新UIBarButtonItem替换UINavigationItem中的backBarButtonItem。

To fix that you have to reset the Back Indicator's Frame to hold the size of your image. Another option is to create a UIButton with the right frame size and image and assign to a UIBarButtonItem. Then you can replace the backBarButtonItem from your UINavigationItem with the new UIBarButtonItem you created.

这篇关于iOS 7:自定义后退指示图像位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆