看看:http://www.raywenderlich.com/21703/user-interface-customization-in-ios-6
和:http://iosdevblog.com/2013/01/26/the-recommended-size-for-custom-uibarbuttonitem/
您需要爲您的按鈕創建一個自定義透明的背面圖像,並將其設置爲欄按鈕爲iOS 6的背景圖像:
[[UIBarButtonItem appearance] setBackgroundImage:clearImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackgroundImage:clearImage forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
//編輯:我首先以爲它是一個後退按鈕,您需要像下面這樣調整大小:
UIImage *buttonBack30 = [clearImage resizableImageWithCapInsets:UIEdgeInsetsMake(0, 10, 0, 6)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonBack30 forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
我創建clearImage用下面的代碼,但你完全可以創建任何顏色的34x60圖像:
+ (UIImage *)imageWithColor:(UIColor *)color andSize:(CGRect)rect {
// Create a 1 by 1 pixel context
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
[color setFill];
UIRectFill(rect); // Fill it with your color
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
UIImage *clearImage = [self imageWithColor:[UIColor clearColor] andSize:CGRectMake(0, 0, 34, 60)];
[[UIBarButtonItem appearance] setBackgroundImage:backgroundImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackgroundImage:backgroundImage forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
謝謝你,它看起來像它要解決我的問題,所以我要在我的應用程序適用於整個ButtonItem代替iOS6的 –
正確的作品你可以申請的,僅適用於iOS 6: 如果([[[的UIDevice currentDevice] systemVersion]的floatValue] <7) – Diwann