Remove border for UIPopoverController

人盡茶涼 提交于 2019-11-28 06:28:03

问题


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


回答1:


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.




回答2:


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];
    }
}


来源:https://stackoverflow.com/questions/4710436/remove-border-for-uipopovercontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!