Skip to content

Instantly share code, notes, and snippets.

@tikitikipoo
Created February 13, 2012 01:52
Show Gist options
  • Save tikitikipoo/1812628 to your computer and use it in GitHub Desktop.
Save tikitikipoo/1812628 to your computer and use it in GitHub Desktop.
UIToolbarに背景画像を設定。iOS5とiOS4に対応する方法。
// 出所:http://stackoverflow.com/questions/6341503/uinavigationbar-custom-background-image
// 関連:http://www.mladjanantic.com/setting-custom-background-for-uinavigationbar-what-will-work-on-ios5-and-ios4-too/
toolBar = [[UIToolbar alloc] initWithFrame:toolBarBounds];
[toolBar sizeToFit];
// set BackgroudImage
if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) {
//iOS 5
if ([toolBar respondsToSelector:@selector(setBackgroundImage:forToolbarPosition:barMetrics:)]) {
[toolBar setBackgroundImage:[UIImage imageNamed: @"black.png"]
forToolbarPosition:UIToolbarPositionAny
barMetrics:UIBarMetricsDefault];
}
} else {
//iOS 4
[toolBar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"black.png"]] autorelease] atIndex:0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment