ios - 如何水平定位 UINavigationBar 中的 backIndicatorImage

标签 ios objective-c uinavigationbar uiedgeinsets

我使用此代码将插图添加到导航栏的 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。

关于ios - 如何水平定位 UINavigationBar 中的 backIndicatorImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34595468/

相关文章:

uinavigationbar - iOS 11 导航栏中的搜索栏

ios - 使用 overCurrentContext 呈现 View Controller ,然后推送到导航堆栈会导致导航栏重叠

iOS 人员选择器更改按钮颜色

ios - APPDelegate 中的 openURL 转换错误 NSString -> String (Swift & iOS8)

ios - PaintCode Canvas 的最佳宽度和高度是多少?

ios - 使用 textField 和 textView 让键盘消失

IOS Swift 如何从不同的 Controller 重新加载 tableView

ios - 在 UITableviewcell 中使用 Collectionview

objective-c - 使用 xcodebuild 的 NSUserdefaults

objective-c - ';' 语句说明符中应为 'for' (iOS)