app delegate中的自定义导航后退按钮

时间:2014-07-22 10:00:33

标签: ios objective-c

我在app delegate.m中使用以下代码在导航栏上设置按钮图像,但它显示3个按钮而不是一个..

[[UIBarButtonItem appearance]setBackButtonBackgroundImage:[[UIImage imageNamed:@"back_icon.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]
                                                      forState:UIControlStateNormal
                                                    barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-100,0) forBarMetrics:UIBarMetricsDefault];

如果我使用以下代码,它会拉伸后退按钮:

[[UIBarButtonItem appearance]setBackButtonBackgroundImage:[UIImage imageNamed:@"back_icon.png"]
                                                      forState:UIControlStateNormal
                                                    barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-100,0) forBarMetrics:UIBarMetricsDefault];

1 个答案:

答案 0 :(得分:0)

你有UIEdgeInsetsMake值的问题,因为使用它你试图重复背景图片,试试这样

UIImage *gradientImage32 = [[UIImage imageNamed:@"selected.png"]
                                resizableImageWithCapInsets:UIEdgeInsetsMake(0, 20, 0, 20)];
[[UIBarButtonItem appearance] setBackgroundImage:gradientImage32 forState:UIControlEventTouchUpInside
                                       barMetrics:UIBarMetricsDefault];