Sunday, 23 March 2014

iPhone Development: Set BackgroundColor of UITableView transparent in IOS7

UITableView is the most common control used in iPhone app development.It basically used for displaying a list in our iPhone application. Though you can customize it  in many different ways as per your app.
To set background color of your UITableView as transparent, we can use

table.backgroundColor = [UIColor clearColor];

The above line of code works well prior to IOS 7. For IOS 7 there is a slight change in layouts made by apple, so for making your UITableView background transparent you can follow given below points

If your UITableView is placed in .xib file then open your .xib file and select your UITableView.
Now on your screen right side there is a property pane, select attribute inspector(shown in picture, one highlighted as blue)

Scroll down and set background property of  tableview  section and view section to clear color(shown in picture below)

Select your .m file and add tableview delegate method -(void)tableView:(UITableView *)tableView
 willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

-(void)tableView:(UITableView *)tableView
 willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
    [cell setBackgroundColor:[UIColor clearColor]];

In the above code, we set cell background color to clear color. Now run your code and you will find that background color of table-view is transparent.

No comments:
Write comments