问题描述
我无法正确设置自定义后退指示器图像.指标未居中!
I'm having trouble setting properly a custom back indicator image. The indicator is not centered!
这是一张照片:
我在 didFinishLaunchingWithOptions:
方法中设置指示器图像...
I'm setting the indicator image in didFinishLaunchingWithOptions:
method...
- (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.然后,您可以将 UINavigationItem 中的 backBarButtonItem 替换为您创建的新 UIBarButtonItem.
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:自定义后退指示器图像位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!