2

In my Ipad application I use a popover but I'm not able to make it transparent. The popover has a tableview inside; my code is:

UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(600, 800, 100, 100)];   
popoverView.backgroundColor = [UIColor greenColor];
popoverContent.view = zoneViewController.view;
self.popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
[self.popoverController presentPopoverFromRect:CGRectMake(1200, -200, 50, 375) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:TRUE];
[[[popoverController contentViewController] view] setAlpha:0.25f];

I'm able to make transparent only the tableview, but popover remains black...why??

Tejaswi Yerukalapudi
  • 8,987
  • 12
  • 60
  • 101
cyclingIsBetter
  • 17,447
  • 50
  • 156
  • 241

4 Answers4

3

I spent hours trying every solution listed on this site to get transparency to work on a UIPopoverController containing a GROUPED UITableView -- NONE of which worked for me:

  1. Put the popover in a parent view and change the alpha on THAT view. (FAILED)
  2. Change the alpha on various combinations of subviews (tableview background, tableview cells, popover background, etc.)
  3. Add background views to the cells and change the alpha on those. (FAILED)
  4. Finally: Change the alpha on EVERY view in the hierarchy starting from the popover content view (FAILED)

There's a black root view in the popover that has an alpha of 1.0 and it doesn't matter what you do with the subviews (or if you stick it in a superview), the transparency doesn't work. So, I crawled up the view hierarchy (by trial and error) until I got to that cursed black view and set ITS alpha explicitly. Success! All I had to add was one line of code AFTER the popover was visible:

self.popoverController.contentViewController.view.superview.superview.superview.alpha = 0.5;

N.B. This solution will likely stop working when Apple makes updates to UIPopoverController, so use at your own risk!

nhahtdh
  • 55,989
  • 15
  • 126
  • 162
Deb Orton
  • 31
  • 2
0

Since iOS 5 you can set custom UIPopoverBackgroundView. Check the discussion at Customizing the UIPopoverController view background and border color

Community
  • 1
  • 1
Evgeny
  • 21
  • 4
0

The popover is by default transparent. If you place subviews into the Popover view, then you must make the subviews' backgroundColor transparent.

So, in your case, you will need to set the tableView's backgroundColor property to [UIColor clearColor] and you will also need to make your tableView cells transparent.

Do not forget to make your cells transparent!

0b10110
  • 29
  • 1
  • 5
0
[[[popoverController contentViewController] view] setAlpha:0.25f];

This modifies the transparency of zoneViewController's view, which will be nested inside the Popover. However, there's currently no way for you to customize the appearance of the Popover itself. You can control the size and arrow direction, but not the border color or border transparency of the Popover.

If you really want a transparent Popover frame, you'll have to write your own.

Related: How to customize / style a UIPopoverController

Community
  • 1
  • 1
Stephen Poletto
  • 3,645
  • 24
  • 24
  • I don't want control the border color o border transparency but only the transparency of tableview background. If I set alpha = 0 of my tableview with this code: [[[popoverController contentViewController] view] setAlpha:0.25f]; I see popover all black...and how can I set alpha of popover background?? Do it remain ever black? – cyclingIsBetter Apr 01 '11 at 07:39
  • @blackguardian - The background color of the popover cannot be customized either. You'll probably have to write your own popover class (which shouldn't be too difficult) if you want transparency. – Stephen Poletto Apr 01 '11 at 09:05
  • then finally you tell me that I can't ever have a popover with transparence effect...is it right? – cyclingIsBetter Apr 01 '11 at 09:32
  • @blackguardian - Not via the provided API for UIPopoverController. You'd have to make your own custom popover class. – Stephen Poletto Apr 01 '11 at 09:36