2

In my application, i am presenting an UITableViewController class (Grouped style) to the user for the particular scenario. I want to show the table view's cells only. The background should be transparent so that the user can see the previous page.

I tried with the following codes in viewDidLoad method of the table view controller. But they are not working..

self.tableView.backgroundColor = [UIColor clearColor];

self.tableView.opaque = NO;

self.tableView.backgroundView = nil;

Is it possible to show the cells with a dimmed background?

Thanks in Advance

Confused
  • 3,846
  • 7
  • 45
  • 72
  • what do you mean by dimmed background? light grey color or something ? – Jean-Luc Godard Sep 13 '11 at 12:09
  • I dont understand what do you mean by displaying previous page on tableview's background to user !! – Manoj Sep 13 '11 at 12:22
  • I want the background like [link] (http://www.google.co.in/imgres?q=uisearchdisplaycontroller&um=1&hl=en&sa=N&tbm=isch&tbnid=qtDucy4yKONDcM:&imgrefurl=http://www.cocoachina.com/iphonedev/sdk/2009/0726/327.html&docid=MaLPkY5XsNHBtM&w=414&h=770&ei=7E5vTv_RLcGyrAer29ShBw&zoom=1&iact=hc&vpx=184&vpy=246&dur=4923&hovh=306&hovw=164&tx=107&ty=158&page=1&tbnh=169&tbnw=91&start=0&ndsp=20&ved=1t:429,r:13,s:0&biw=1280&bih=666) – Confused Sep 13 '11 at 12:40

2 Answers2

8

I use: (in viewDidLoad)

   self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.opaque = NO;

Then in cellForRowAtIndexPath:

cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.detailTextLabel.backgroundColor = [UIColor clearColor];
    cell.backgroundColor = [UIColor colorWithWhite:1 alpha:.55];

Not sure if this is what you wanted, but it gives you the option to make everything clear. (obviously the alpha would change for your case, but that measures theo pacity of the cells)

Michael M
  • 1,034
  • 2
  • 8
  • 21
  • Thanks for your reply.. Changing Alpha value will affect only the cell's background alone. I'm asking about table view's background's transparency. When you present a view/table view modally, the line `self.tableView.backgroundColor = [UIColor clearColor];` or setting a alpha value for `self.tableView` does not works. :( – Confused Sep 14 '11 at 04:32
  • so you want the background to be the previous page with, say 50% alpha, to give it the effect like its 'popped up'? – Michael M Sep 15 '11 at 12:59
  • what about [this?](http://stackoverflow.com/questions/1008246/how-to-create-a-uitableviewcell-with-a-transparent-background). The code is something like: UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; backView.backgroundColor = [UIColor clearColor]; cell.backgroundView = backView; – Michael M Sep 15 '11 at 13:04
1

Just altering the tableView doesn't help. You have to mess with the cells also. Inside the cellForRowAtIndexPath:(NSIndexPath *)indexPath method, put this before the return statement:

UIView * bgView =[[UIView alloc] initWithFrame:CGRectZero] autorelease];
bgView.backgroundColor = [UIColor clearColor];
cell.backgroundView = bgView;
dragonfly
  • 411
  • 3
  • 11