I have my current base sdk set to iOS 4.2.
I have this method:
- (void) setNavigationBarBackground
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) {
//iOS 5.0
if ([self respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
{
[self setBackgroundImage:[UIImage imageNamed:kImageNavBar] forBarMetrics:UIBarMetricsDefault];
}
}
else
{
//iOS 4.whatever and below
UIImageView *imageView = (UIImageView *)[self viewWithTag:kNavigationBarBackgroundImageTag];
if (imageView == nil)
{
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:kImageNavBar]];
[imageView setTag:kNavigationBarBackgroundImageTag];
[self insertSubview:imageView atIndex:0];
[imageView release];
}
}
}
When I build my project, i encounter a compile-time error as:
'UIBarMetrics' Default undeclared (first use in this function)
When I set my base sdk to 5.0, it compiles without any error.
Does anybody know how can I compile it using base sdk 4.2?
for specifically your case, use this:
In general, a good way to conditionally compile across various SDK versions is this:
put this at the top (along with imports):
then if there are some OS specific features, use them like this (I am using AlertView as an example. Pre iOS5, UIAlertView does not support a custom textView inside it, so I had my own custom AlertView. In iOS5, that hack does not work and I have to use UIAlertView as it supports custom textViews):
Hope it helps