我在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];
答案 0 :(得分:0)
你有UIEdgeInsetsMake
值的问题,因为使用它你试图重复背景图片,试试这样
UIImage *gradientImage32 = [[UIImage imageNamed:@"selected.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 20, 0, 20)];
[[UIBarButtonItem appearance] setBackgroundImage:gradientImage32 forState:UIControlEventTouchUpInside
barMetrics:UIBarMetricsDefault];