My application i will give deployment target 6.1 so in 7.0 display and 6.1 display screen different so how to adjust the size in both 6.1 and 7.0
Main UI difference in iOS 6 and iOS 7 is that status bar is included inside the viewcontroller in iOS 7. it means your view controller is 20 px greater than iOS6. you have to adjust your items.
First design your items according to iOS 6 which is better way and you must have a lot of practice of doing that, now set Δy to 20 for every item.
Or design your items according to iOS 7 and set Δy to -20
use ios7.0 and later and then handle the secrren size using autolayout
Add this code in your AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Whatever your code goes here
if(kDeviceiPad){
//adding status bar for IOS7 ipad
if (IS_IOS7) {
UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, 1024, 20);
addStatusBar.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; //change this to match your navigation bar
[self.window.rootViewController.view addSubview:addStatusBar];
}
}
else{
//adding status bar for IOS7 iphone
if (IS_IOS7) {
UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, 320, 20);
addStatusBar.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; //You can give your own color pattern
[self.window.rootViewController.view addSubview:addStatusBar];
}
return YES;
}
It may be helpful
-(void)adjustFrameForiOS7:(UIView*)v
{
if([UIDevice currentDevice].systemVersion.floatValue >=7.0)
{
[v setFrame:CGRectMake(v.frame.origin.x, v.frame.origin.y+20, v.frame.size.width, v.frame.size.height)];
}
else
{
[v setFrame:CGRectMake(v.frame.origin.x, v.frame.origin.y, v.frame.size.width, v.frame.size.height)];
}
}
Related
I have a class inherit from UINavigationBar and I want to add a separator line as its subview to separate the navigation bar and the navigation content.
The line's height is defined as following.
#define SEPERATOR_LINE_HEIGHT (1.0f / [UIScreen mainScreen].scale)
My code:
#interface MyPopNavigationBar : UINavigationBar
#end
#implementation MyPopNavigationBar {
UIView *separatorLine;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.clipsToBounds = YES;
self.translucent = NO;
separatorLine = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(self.bounds) - SEPERATOR_LINE_HEIGHT, CGRectGetWidth(self.bounds), SEPERATOR_LINE_HEIGHT)];
separatorLine.backgroundColor = [UIColor redColor];
separatorLine.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
[self addSubview:separatorLine];
}
return self;
}
This works well in both iOS 6 and iOS 8 (all Retina), but I can't see my separatorLine in iOS 7 (Retina, too)!
iOS 6 & 8:
iOS 7:
Besides, when I tried to set the separator line height to exact 1, it shows in all iOS versions.
separatorLine = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(self.bounds) - 1, CGRectGetWidth(self.bounds), 1)];
What's wrong?
Solved this by myself. It's the autoresizingMask's fault 😂. I strongly suspect this a bug of iOS7.
I print the recursiveDescription in lldb, only to find the height of separatorLine is autoresized to zero in iOS7! In contrast, the value is 0.5 in iOS8.
So, remove this line:
separatorLine.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
And set the frame in layoutSubviews method of MyPopNavigationBar again to make it correct:
- (void)layoutSubviews {
[super layoutSubviews];
separatorLine.frame = CGRectMake(0, CGRectGetHeight(self.bounds) - SEPERATOR_LINE_HEIGHT, CGRectGetWidth(self.bounds), SEPERATOR_LINE_HEIGHT);
}
Then the line displays in all iOS versions.
I have a UINavigationController to which I need to add a second UINavigationBar. Neither of those bars is translucent. Problem is, view controllers that I put inside this navigation controller are partially covered by my second navigation bar. Where do I adjust the frames of those view controllers' views so that I don't get a "blinking" effect of them changing frames while being visible?
EDIT:
This is in viewDidLoad:
UINavigationBar *secondaryNavBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, 50)];
secondaryNavBar.translucent = NO;
if ([secondaryNavBar respondsToSelector:#selector(setBarTintColor:)]) { //it has to work on iOS 6 as well
secondaryNavBar.barTintColor = [UIColor darkGrayColor];
secondaryNavBar.tintColor = [UIColor whiteColor];
}
else {
secondaryNavBar.tintColor = [UIColor darkGrayColor];
}
[self.view addSubview:secondaryNavBar];
self.secondaryNavBar = secondaryNavBar;
Here's a working solution. Certainly not the best, and I did not make it to support iOS 6, you'll have to work on it and test it.
CustomNavigationController.m :
#implementation CustomNavigationController {
UINavigationBar *bottomNavBar;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self showNavBar];
}
- (void)showNavBar {
UINavigationBar *secondaryNavBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, 50)];
secondaryNavBar.translucent = NO;
if ([secondaryNavBar respondsToSelector:#selector(setBarTintColor:)]) { //it has to work on iOS 6 as well
secondaryNavBar.barTintColor = [UIColor darkGrayColor];
secondaryNavBar.tintColor = [UIColor whiteColor];
}
else {
secondaryNavBar.tintColor = [UIColor darkGrayColor];
}
[self.view addSubview:secondaryNavBar];
bottomNavBar = secondaryNavBar;
[self layoutNavBar];
}
- (void)layoutNavBar {
// Get the currently displayed view
UIView *contentView = self.topViewController.view;
// Get its frame and height
CGRect contentFrame = contentView.frame;
float height = contentFrame.size.height;
// Adapt height and y origin with the new nav bar
contentFrame.size.height = height - bottomNavBar.frame.size.height;
contentFrame.origin.y = bottomNavBar.frame.origin.y + bottomNavBar.frame.size.height;
// Set the view's frame
contentView.frame = contentFrame;
}
#end
ViewController.m :
#implementation ViewController
-(void)viewDidAppear:(BOOL)animated {
CustomNavigationController *navigation = (CustomNavigationController*)self.navigationController;
[navigation layoutNavBar];
}
#end
Note that you have to call layoutNavBar on viewDidAppear, or the view's frame will be reset by your app. This is not a perfectly clean solution, but a pretty good fix.
I want my UINavigationBar to rotate properly within my SignatureViewController. This is currently how it looks in Portrait vs Landscapemode when rotating: http://tinypic.com/view.php?pic=2w5573a&s=5#.Uk5kgYapWrg
As you can see the UINavigationBar does not scale on the width when in landscape. My project is built as following:
rootViewController(UINavgationController) ------Modal push-----> SignatureViewController
(portrait only) (portrait/landscape)
Note that I am not using a normal push to the SignatureViewController, I am using a modal one. Just in case I wanna mention this because I am not sure if it can affect the outcome in any strange way?... I have tried different approaches to change the background of the NavigationBar depending on if it is in landscape or portrait. I will post some here below:
try nr1: Not working
- (void) viewWillAppear:(BOOL)animated {
[[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:#"bar_nav_black.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:#"navbar25g.png"] forBarMetrics:UIBarMetricsLandscapePhone];
[[UINavigationBar appearance] setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
}
try nr2: Not working
- (void) viewWillAppear:(BOOL)animated {
UIImage *navBarLandscape = [[UIImage imageNamed:#"navbar25g.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(x,x,x,x)];
[[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:#"bar_nav_black.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance]setBackgroundImage:navBarLandscape forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
}
try nr3: Not working
- (void)applicationDidChangeStatusBarOrientation:(NSNotification *)notification
{
UIView *v = [[UIView alloc]init];
int a = [[notification.userInfo objectForKey: UIApplicationStatusBarOrientationUserInfoKey] intValue];
int w = [[UIScreen mainScreen] bounds].size.width;
int h = [[UIScreen mainScreen] bounds].size.height;
switch(a){
case 4:
v.frame = CGRectMake(0,20,w,h);
[[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:#"bar_nav_black.png"] forBarMetrics:UIBarMetricsDefault];//Have also tried with UIBarMetricsLandscapePhone...
NSLog(#"willrotate:1");
break;
case 3:
v.frame = CGRectMake(-20,0,w-20,h+20);
[[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:#"navbar25g.png"] forBarMetrics:UIBarMetricsDefault];//Have also tried with UIBarMetricsLandscapePhone...
NSLog(#"willrotate:2");
[self.view addSubview:v];
break;
case 2:
v.frame = CGRectMake(0,-20,w,h);
[[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:#"bar_nav_black.png"] forBarMetrics:UIBarMetricsDefault];//Have also tried with UIBarMetricsLandscapePhone...
NSLog(#"willrotate:3");
break;
case 1:
v.frame = CGRectMake(20,0,w-20,h+20);
NSLog(#"willrotate:4");
[[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:#"navbar25g.png"] forBarMetrics:UIBarMetricsDefault];//Have also tried with UIBarMetricsLandscapePhone...
}
Note that in try nr3 the NSLog works but it refuses to change the background of the UINavigationBar. So, any ideas what I shall do from here ? / Regards
can you please try to implement the UINavigationBar class and override one drawRect: method
it should work
#implementation UINavigationBar (BackgroundImage)
- (void)drawRect:(CGRect)rect
{
UIImage *navimage;
//we will check if screen width is 320 then it will be potrait
if(self.frame.size.width == 320)
{
navimage = [UIImage imageNamed: #"Your Potrait nav bar image"];
}
else
{
navimage = [UIImage imageNamed: #"Your Landscape nav bar image"];
}
[navimage drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
#end
Hope it helps...
and just try this for nr1 and nr2
just change the last line of code with this..if its working or not...let me know
self.navigationController.navigationBar.autoresizingMask = UIViewAutoresizingFlexibleTopMargin; //UIViewAutoresizingFlexibleWidth
I have an app with a support landscape and portrait mode. And I need the same behavior status bar like on iOS 6. What is the simplest way to do this?
I've tried the solutions in Stack Overflow question iOS 7 status bar back to iOS 6 style?, but it doesn't work. My subview depend on the view size, and my view doesn't stretch correctly. I don't want to update my XIB files; I simply want to add something that helps me. I don't know what it may be (hack or prayers).
You can try writing this in your ViewWillappear or DidAppear. Here we are shifting the view frame 20 pixels down.
CGRect frame = self.view.frame;
frame.origin.y = 20;
if (self.view.frame.size.height == 1024 ||
self.view.frame.size.height == 768)
{
frame.size.height -= 20;
}
self.view.frame = frame;
This will work, but however this is not a very good idea. You can also change the text colour of the status bar to light or dark depending on your app background by calling the following method if it helps.
-(UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent; // For light status bar
return UIStatusBarStyleDefault // For Dark status bar
}
If you are on Xcode 5 and you are installing in iOS 7 then sorry, this will not happen (as far as I know).
If you want to see the status bar on iOS 7 like iOS 6 than open your project in Xcode 4.x.x and install in iOS 7. One problem with this approach I found is that sometimes Xcode 4.x.x doesn't recognise an iOS 7 device.
But if your Xcode 4.x.x can show your iOS 7 device then it will work.
The .api generated from Xcode 4.x.x will work in both iOS 6 and iOS 7, but you will not get extra space (of the status bar) on iOS 7 and the new look of keyboard, picker, switch, etc. But yes, you will get the new UIAlertView (I don't know why this is new and the other controls are old.)
I hope we will soon get a better solution in Xcode 5 for this.
UPDATE:
I found the way to run the app from Xcode 5 as Xcode 4. This is just matter of the base SDK.
If you want to built as Xcode 4 (iOS 6 SDK) from Xcode 5 then do the following.
Close Xcode 4 and 5.
In Xcode 4 Go to
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs
Here you will find iPhoneOS6.1.sdk. Copy this folder. And now go in Xcode 5 on the same path. In Xcode 5, you will find iPhoneOS7.0.sdk. Paste iPhoneOS6.1.sdk with it.
Now close the Finder and launch Xcode 5. Go to project target setting -> Build Setting and find Base SDK. Select iOS 6.1 as Base SDK. This will also work for 6.0. You just need to find iPhoneOS6.0.sdk.
Now you will see the device name twice in the run dropdown box. One for SDK 7.0 and one for SDK 6.1. So now you can run both ways with iOS 6 SDK and iOS 7 SDK.
I hope this will help someone.
I recently had to solve a similar problem, and I approached it in a slightly different way...
The approach was to use an extra view controller that acted as a container view controller for what was originally my rootViewController. First, i set up a container like this:
_containerView = [[UIView alloc] initWithFrame:[self containerFrame]];
_containerView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
_containerView.clipsToBounds = YES;
[self.view addSubview:_containerView];
[self.view setBackgroundColor:[UIColor blackColor]];
[UIApplication.sharedApplication setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
where the containerFrame was defined like this:
- (CGRect)containerFrame
{
if ([MyUtilityClass isSevenOrHigher])
{
CGFloat statusBarHeight = [MyUtility statusBarHeight]; //20.0f
return CGRectMake(0, statusBarHeight, self.view.bounds.size.width, self.view.bounds.size.height - statusBarHeight);
}
return self.view.bounds;
}
Finally, I added what was originally my rootViewController as a childViewController of the new one:
//Add the ChildViewController
self.childController.view.frame = self.containerView.bounds;
self.childController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self addChildViewController:self.childController];
[self.containerView addSubview:self.childController.view];
[self.childController didMoveToParentViewController:self];
Things to note:
- Modal view controllers will still be presented in the iOS7 style, so I still have to account for that somehow.
Hope this helps someone!
This Guide helps me.
http://www.doubleencore.com/2013/09/developers-guide-to-the-ios-7-status-bar/
The most robust way to handle the 20 point size difference is Auto Layout.
If you aren’t using Auto Layout, Interface Builder provides you with tools to handle the screen size difference between iOS 7 and the older versions. When Auto Layout is turned off, you will notice an area in the sizing tab of the utility area (right pane) of Interface Builder that allows you to set iOS 6/7 Deltas.
1) It's a hack, but it works!
Use it if you doesn't use UIAlertView or KGStatusBar!!!
#import <objc/runtime.h>
#interface UIScreen (I_love_ios_7)
- (CGRect)bounds2;
- (CGRect)boundsForOrientation:(UIInterfaceOrientation)orientation;
#end
#implementation UIScreen (I_love_ios_7)
- (CGRect)bounds2
{
return [self boundsForOrientation:[[UIApplication sharedApplication] statusBarOrientation]];
}
- (CGRect)boundsForOrientation:(UIInterfaceOrientation)orientation
{
CGRect resultFrame = [self bounds2];
if(UIInterfaceOrientationIsLandscape(orientation))
resultFrame.size.width -= 20;
else
resultFrame.size.height -= 20;
return resultFrame;
}
#end
void Swizzle(Class c, SEL orig, SEL new)
{
Method origMethod = class_getInstanceMethod(c, orig);
Method newMethod = class_getInstanceMethod(c, new);
if(class_addMethod(c, orig, method_getImplementation(newMethod), method_getTypeEncoding(newMethod)))
class_replaceMethod(c, new, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
else
method_exchangeImplementations(origMethod, newMethod);
}
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
Swizzle([UIScreen class], #selector(bounds2), #selector(bounds));
[application setStatusBarStyle:UIStatusBarStyleLightContent];
self.window.clipsToBounds =YES;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(applicationDidChangeStatusBarOrientation:)
name:UIApplicationWillChangeStatusBarOrientationNotification
object:nil];
NSDictionary* userInfo = #{UIApplicationStatusBarOrientationUserInfoKey : #([[UIApplication sharedApplication] statusBarOrientation])};
[[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationWillChangeStatusBarOrientationNotification
object:nil
userInfo:userInfo];
}
return YES;
}
- (void)applicationDidChangeStatusBarOrientation:(NSNotification *)notification
{
UIInterfaceOrientation orientation = [[notification.userInfo objectForKey: UIApplicationStatusBarOrientationUserInfoKey] intValue];
CGSize size = [[UIScreen mainScreen] boundsForOrientation:orientation].size;
int w = size.width;
int h = size.height;
float statusHeight = 20.0;
switch(orientation){
case UIInterfaceOrientationPortrait:
self.window.frame = CGRectMake(0,statusHeight,w,h);
break;
case UIInterfaceOrientationPortraitUpsideDown:
self.window.frame = CGRectMake(0,0,w,h);
break;
case UIInterfaceOrientationLandscapeLeft:
self.window.frame = CGRectMake(statusHeight,0,w,h);
break;
case UIInterfaceOrientationLandscapeRight:
self.window.frame = CGRectMake(0,0,w,h);
break;
}
}
#end
2) Create category, and always use contentView instead of view
#interface UIViewController(iOS7_Fix)
#property (nonatomic, readonly) UIView* contentView;
- (void)updateViewIfIOS_7;
#end
#implementation UIViewController(iOS7_Fix)
static char defaultHashKey;
- (UIView *)contentView
{
return objc_getAssociatedObject(self, &defaultHashKey)?: self.view;
}
- (void)setContentView:(UIView *)val
{
objc_setAssociatedObject(self, &defaultHashKey, val, OBJC_ASSOCIATION_RETAIN_NONATOMIC) ;
}
- (void)updateViewIfIOS_7
{
if([[[UIDevice currentDevice] systemVersion] floatValue] < 7 || objc_getAssociatedObject(self, &defaultHashKey))
return;
UIView* exchangeView = [[UIView alloc] initWithFrame:self.view.bounds];
exchangeView.autoresizingMask = self.view.autoresizingMask;
exchangeView.backgroundColor = [UIColor blackColor];
UIView* view = self.view;
if(self.view.superview){
[view.superview addSubview:exchangeView];
[view removeFromSuperview];
}
[exchangeView addSubview:view];
self.view = exchangeView;
CGRect frame = self.view.bounds;
frame.origin.y += 20.0;
frame.size.height -= 20.0;
view.frame = frame;
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self setContentView:view];
}
In every UIViewController:
- (void)viewDidLoad
{
[super viewDidLoad];
[self updateViewIfIOS_7];
UILabel* lab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 130, 30)];
lab.backgroundColor = [UIColor yellowColor];
[self.contentView addSubview:lab];
//...
}
I was just testing my app with iOS 6.0 and Xcode 4.5GM and I have set up a view like this:
[self.view setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
So, the view has the same pattern than a common table view.
This works fine on iOS 4 and 5, but in iOS 6 it just gives me a white background.
Is this deprecated? If so, how can I replace it?
Thanks
This method will be deprecated during the 6.0 seed program
If you want to have a background in your own view that looks like the table view background,
then you should create an empty table view and place it behind your content.
First, add this to your viewDidLoad:
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"tableViewBackground.png"]];
OR
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"tableViewBackground.png"]];
Then add this images to your app:
tableViewBackground.png
tableViewBackground#2x.png
I've written a UIColor category to replace groupTableViewBackgroundColor:
#interface UIColor (UITableViewBackground)
+ (UIColor *)groupTableViewBackgroundColor;
#end
#implementation UIColor (UITableViewBackground)
+ (UIColor *)groupTableViewBackgroundColor
{
__strong static UIImage* tableViewBackgroundImage = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
UIGraphicsBeginImageContextWithOptions(CGSizeMake(7.f, 1.f), NO, 0.0);
CGContextRef c = UIGraphicsGetCurrentContext();
[[self colorWithRed:185/255.f green:192/255.f blue:202/255.f alpha:1.f] setFill];
CGContextFillRect(c, CGRectMake(0, 0, 4, 1));
[[self colorWithRed:185/255.f green:193/255.f blue:200/255.f alpha:1.f] setFill];
CGContextFillRect(c, CGRectMake(4, 0, 1, 1));
[[self colorWithRed:192/255.f green:200/255.f blue:207/255.f alpha:1.f] setFill];
CGContextFillRect(c, CGRectMake(5, 0, 2, 1));
tableViewBackgroundImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
});
return [self colorWithPatternImage:tableViewBackgroundImage];
}
#end
This solution also allows to tweak the appearance of the background. Feel free to change the drawing code :)
In iOS6 SKD, comments in UIInterface.h suggest the following:
Group style table view backgrounds can no longer be represented by
a simple color.
If you want to have a background in your own view
that looks like the table view background, then you should create
an empty table view and place it behind your content.
This method will be deprecated during the 6.0 seed program
A simple solution is to set the background with equivalent RGB values:
[self.view setBackgroundColor:[UIColor colorWithRed:215.0/255.0 green:217.0/255.0 blue:223.0/255.0 alpha:1.0]];
You can them set the view background to color to White or whatever you like in the xib to suppress the warning.
If it helps anyone, here's specifically what I'm doing in my custom view to get this background (using hint from Mr Beloeuvre)
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
UITableView *tv = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
[self.view addSubview:tv];
[self.view sendSubviewToBack:tv];
// ...
}
Try this:
[myTableView setBackgroundView:nil];
[myTableView setBackgroundView:[[[UIView alloc] init] autorelease]];
You may have difficult time to locate the view if you use storyboard and have many views. You can click on "Show the Version editor" button the right top corner. This will change story view to XML text view. Search for "groupTableViewBackGroundColor". You should find views with this attribute.
It's good idea to use standard methods for previous iOs versions. So I improved solution of James Boutcher:
+ (void)setBackgroundColorForTableView:(UITableView*) tableView
{
UIColor* color = [UIColor whiteColor];
NSString* version = [[UIDevice currentDevice] systemVersion];
if([version floatValue] < 6.0)
{
tableView.backgroundColor = color;
}
else
{
tableView.backgroundView = nil;
UIView* bv = [[UIView alloc] init];
bv.backgroundColor = color;
tableView.backgroundView = bv;
[bv release];
}
}
Elaborating on #NSElvis's solution, here is the identical grouped table view background asset (it's wide enough so you don't get funny effects in landscape orientation)
back-tableview#2x.png
To use it, simply do
[YOUR_VIEW setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"back-tableview"]]];