UIToolbar setBackgroundImage
- (void)setBackgroundImage:(UIImage *)backgroundImage forToolbarPosition:(UIToolbarPosition)topOrBottom barMetrics:(UIBarMetrics)barMetrics
Parameters of [UIToolbar setBackgroundImage]
backgroundImage
The image to use for the toolbar background in the position specified by topOrBottom and with the metrics specified by barMetrics.
topOrBottom
A toolbar position constant.
barMetrics
A bar metrics constant.
UIToolbar setBackgroundImage example.
if([navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) {
//iOS 5 new UINavigationBar custom background
[navigationBar setBackgroundImage:image forBarMetrics: UIBarMetricsDefault];
}
To realize this, take a look at here iOS 4.3 to iOS 5.0 API Differences and search for "UINavigationBar.h"
//iOS 5 new UINavigationBar custom background
[navigationBar setBackgroundImage:image forBarMetrics: UIBarMetricsDefault];
}
To realize this, take a look at here iOS 4.3 to iOS 5.0 API Differences and search for "UINavigationBar.h"
Example of [UIToolbar setBackgroundImage].
//toolBar background image set based on iOS version
[[UIDevice currentDevice] systemVersion];
if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) {
//iOS 5
UIImage *toolBarIMG = [UIImage imageNamed: @"toolBar_brown.png"];
if ([toolBar respondsToSelector:@selector(setBackgroundImage:forToolbarPosition:barMetrics:)]) {
[toolBar setBackgroundImage:toolBarIMG forToolbarPosition:0 barMetrics:0];
}
} else {
//iOS 4
[toolBar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"toolBar_brown.png"]] autorelease] atIndex:0];
}
[[UIDevice currentDevice] systemVersion];
if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) {
//iOS 5
UIImage *toolBarIMG = [UIImage imageNamed: @"toolBar_brown.png"];
if ([toolBar respondsToSelector:@selector(setBackgroundImage:forToolbarPosition:barMetrics:)]) {
[toolBar setBackgroundImage:toolBarIMG forToolbarPosition:0 barMetrics:0];
}
} else {
//iOS 4
[toolBar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"toolBar_brown.png"]] autorelease] atIndex:0];
}
UIToolbar setBackgroundImage example.
// Set the background image for PortraitMode
[self.toolbar setBackgroundImage:[UIImage imageNamed:@"Sample.png"]
forBarMetrics:UIBarMetricsDefault];
// and For LandscapeMode
[self.toolbar setBackgroundImage:[UIImage imageNamed:@"Sample.png"]
forBarMetrics:UIBarMetricsLandscapePhone];
[self.toolbar setBackgroundImage:[UIImage imageNamed:@"Sample.png"]
forBarMetrics:UIBarMetricsDefault];
// and For LandscapeMode
[self.toolbar setBackgroundImage:[UIImage imageNamed:@"Sample.png"]
forBarMetrics:UIBarMetricsLandscapePhone];