MonoTouch UITableViewController transparent background

By July 24, 2012Blog

Just came across a problem to have UITableViewController on a custom texture, wanted and needed to have the nice rounded corners as well and found out it is not that straightforward to set the background color to transparent in case that running on iPad (3.2 and 4.2 as well).

So here is a little code snippet that does the trick.

 

// create the UITableViewController
SettingTableViewController tableController = new SettingTableViewController(UITableViewStyle.Grouped);
 
// set its color to transparent as well, as this is needed, this is the first layer of the setup
tableController.View.BackgroundColor = UIColor.Clear;
tableController.View.Frame = new RectangleF(12, 101, 280, 98);
 
// create a dummy view for the underlaying view			
UIView view = new UIView();
view.Frame = tableController.View.Frame;
 
// make its color transparent as well
view.BackgroundColor = UIColor.Clear;
 
// and now the little trick, get to the core of the view hierarchy and set the view from the original UIImageView, in which the UITableView of the controller lays, to our custom transparent view
((UITableView)tableController.View).BackgroundView = view;
 
 

 

Happy coding!