Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS popover how to remove the shade

Whenever we show popover the neighbhouring areas show different kind of gray color and the active tab bar icon color changes from blue to gray till pop over is there.

when the popover is dismissed , the grey shade gets removed

I would like to remove the color when the the popover is visible

I googled but I couldn't find anyway seems like this default behaviour.

any help to help me fix the problem is appreciated

Thanks

like image 235
Elstine P Avatar asked May 19 '18 16:05

Elstine P


2 Answers

For achieve this, you can create own custom popover background of UIPopoverBackgroundView. you can find the below code for creating custom CustomPopoverBgView.

CustomPopoverBgView.h

#import <UIKit/UIKit.h>
    @interface CustomPopoverBgView : UIPopoverBackgroundView
{
    UIImageView *_borderImageView;
    UIImageView *_arrowView;
    CGFloat _arrowOffset;
    UIPopoverArrowDirection _arrowDirection;
}
@end

CustomPopoverBgView.m

#import "CustomPopoverBgView.h"
#define CONTENT_INSET 10.0
#define CAP_INSET 25.0
#define ARROW_BASE 25.0
#define ARROW_HEIGHT 25.0
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        self.layer.shadowColor = [[UIColor clearColor] CGColor];
        _borderImageView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"popover-bg.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(CAP_INSET,CAP_INSET,CAP_INSET,CAP_INSET)]];

        _arrowView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow.png"]];

        [self addSubview:_borderImageView];
        [self addSubview:_arrowView];
    }
    return self;
}
+(UIEdgeInsets)contentViewInsets{
    return UIEdgeInsetsMake(CONTENT_INSET, CONTENT_INSET, CONTENT_INSET, CONTENT_INSET);
}

+(CGFloat)arrowHeight{
    return ARROW_HEIGHT;
}

+(CGFloat)arrowBase{
    return ARROW_BASE;
}
- (CGFloat) arrowOffset {
    return _arrowOffset;
}

- (void) setArrowOffset:(CGFloat)arrowOffset {
    _arrowOffset = arrowOffset;
}
- (void)setArrowDirection:(UIPopoverArrowDirection)arrowDirection {
    _arrowDirection = arrowDirection;
}
- (UIPopoverArrowDirection)arrowDirection {
    return _arrowDirection;
}
@end

Calling of CustomPopoverBgView in UIPopoverController

 UIButton *btn = (UIButton *)sender;
 ViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"dddddd"];
 controller.view.backgroundColor = [UIColor redColor];
 UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:controller] ;

 popoverController.popoverBackgroundViewClass = [CustomPopoverBgView class];
[popoverController presentPopoverFromRect:btn.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:true];

Hope this will help you.

like image 59
MobileMatrix Avatar answered Nov 04 '22 09:11

MobileMatrix


Create your own custom popover view and add it as a subview on top of your main view instead of the default one Apple provided.

like image 42
rak appdev Avatar answered Nov 04 '22 07:11

rak appdev