我使用此代码将插图添加到backIndicator
导航栏的图像。但是,这仅适用于图像的垂直定位。我只能将图像移至顶部或底部,而不能移至左侧或右侧。看起来左/右插图无效。我不确定可能是什么问题。
UIEdgeInsets insets = UIEdgeInsetsMake(0, 20, 0, 0); //(20,0,0,0) works fine UIImage *backArrowImage = [[UIImage imageNamed:@"Back"] imageWithAlignmentRectInsets:insets]; [[UINavigationBar appearance] setBackIndicatorImage:backArrowImage]; [[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:backArrowImage];
我也试过这个:
UIImage * backArrowImage =[[UIImage imageNamed:@"Back"]resizableImageWithCapInsets:UIEdgeInsetsMake(0, 20, 0, 0) resizingMode:UIImageResizingModeStretch];
如果无法做到这一点,我是否需要返回添加自定义后退按钮?
我已经尝试了很多方法,终于对我有用,您可以重新绘制图片,方法如下:
UIImage *arrow = [UIImage imageNamed:@"Back_Normal"]; UIGraphicsBeginImageContextWithOptions(CGSizeMake(arrow.size.width+10, arrow.size.height), NO, 0); // move the pic by 10, change it to the num you want [arrow drawAtPoint:CGPointMake(10, 0)]; UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
然后将finalImage用作backIndicatorImage。