1

I have a requirement where in I have to display a custom border for UIPopoverController's popover view instead of the default "Black theme" border. Is it possible?

I cannot use the default black border because it doesnt suite the application's color theme.

There is no provision in the SDK to do this. I have also googled to see if someone else have faced this problem and if they have solved it, but with no luck!

Awaiting suggestions.

Thanks, Raj

Raj Pawan Gumdal
  • 7,390
  • 10
  • 60
  • 92
  • 1
    Is not possible. You will have to create your own PopoverController – nacho4d Jan 17 '11 at 06:16
  • Oh! Any pointers on how to create our own PopoverController? Because, it involves not only of adding it as a subview at a particular location, but also to remove it when user taps it outside the pop-over's area. Thanks. – Raj Pawan Gumdal Jan 17 '11 at 06:26
  • 1
    Create a very big transparent view and inside of it you will add your popover. when the big transparent view is touched then it should disappear. Is simple but making it look nice will require a little bit more work(animations, shadows, etc) – nacho4d Jan 17 '11 at 07:13
  • Thanks for the response, I will have to use such round about ways since there is no default support. I was thinking of subclassing UIWindow of my application and overriding -sendEvent method to achieve this. Whichever works. – Raj Pawan Gumdal Jan 17 '11 at 07:28
  • 1
    If you want a gradient and simulate UIAlertView's background then use a uiview as background. Otherwise UIWindow sendEvent approach is better I suppose. – nacho4d Jan 17 '11 at 07:48
  • Yeah, will check out. Thanks for your concern and responses. – Raj Pawan Gumdal Jan 17 '11 at 09:37
  • Raj, were you able to create a popover with UIWindow or with a UIView ? Thanks.. – the Reverend Feb 21 '12 at 03:35

2 Answers2

2

Solved this by using UIView and also by overriding the hitTest in the main rootViewController's view to see if the touch point is outside that view. If so, the event will be consumed to dismiss the new popover, otherwise the event will be forwarded to the new popover.

Raj Pawan Gumdal
  • 7,390
  • 10
  • 60
  • 92
  • Did you added shadow with view.layer.shadow ? – the Reverend Feb 23 '12 at 18:46
  • No, but we can do that, not a big deal. – Raj Pawan Gumdal Feb 24 '12 at 05:56
  • @Jasmine - Sorry I may be late to respond, and I dont have access to that codebase anymore, so unfortunately I cant share the existing code. But let me know if it is very important, I will write down a reusable module, since I remember how to do it, and upload it in Github for future reference of everybody. – Raj Pawan Gumdal Nov 10 '12 at 06:32
  • We have just run into this problem too. Your solution seems very sensible. If you ever do manage to upload it to github, it would be very useful. – emrys57 Dec 04 '12 at 08:11
  • Sorry @emrys57 - Just now searched all over my archives. Unfortunately I dont have access to that codebase anymore where I had implemented it. I dont have time to re-write, if you do write a solution in similar lines please do share. – Raj Pawan Gumdal Dec 04 '12 at 17:28
  • OK! Thanks anyway. I'll see what happens, I'm not the one writing the code. – emrys57 Dec 04 '12 at 17:32
0

add popview as subview, code is:

//!you must define the dimBackgroundView and set view in head file firstly, 

//action for a button,to add set view as a subview
 - (IBAction)openSetting:(id)sender {

    if(!dimBackgroundView)
    {
       dimBackgroundView = [[UIView alloc] initWithFrame:self.view.bounds];
    }
    dimBackgroundView.backgroundColor = [[UIColor clearColor] colorWithAlphaComponent:0.0];

    [self.view addSubview:dimBackgroundView];

    SettingViewController *set = [[SettingViewController alloc]initWithNibName:nil bundle:nil];
    [set.view setFrame:CGRectMake(120, 50, 400, 600)];
    self.setView = set;

    //add shadow
    set.view.layer.shadowOffset = CGSizeMake(3, 3);
    set.view.layer.shadowColor = [UIColor colorWithRed:70.0/255.0 green:70.0/255.0 blue:80.0/255.0 alpha:1.0].CGColor;
    set.view.layer.shadowOpacity = 0.8;

    [self.view addSubview:set.view];
}
//check touch position, if touch position is outside of setview, remove it from superview
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *) event{
    UITouch *touch = [[event allTouches] anyObject];
    if ([self.setView.view superview] && self.dimBackgroundView == touch.view) {
        [self.dimBackgroundView removeFromSuperview];
        [self.setView.view removeFromSuperview];
    }
}
ldehai
  • 594
  • 4
  • 6