How to add dimmed background to a custom UIPopoverBackgroundView

前端 未结 2 1270
旧巷少年郎
旧巷少年郎 2021-02-10 04:44

I am making custom popover by subclassing UIPopoverBackgroundView (using this tutorial) and presenting it by using UIPopoverController. Unfortunately as soon as I specify custom

2条回答
  •  你的背包
    2021-02-10 05:05

    All you need is add next code into initWithFrame: method of your implementation of UIPopoverBackgroundView.

    UIView *dimView = [[UIView alloc] initWithFrame:CGRectMake(0 - self.frame.origin.x,
                                                               0 - self.frame.origin.y,
                                                               [UIScreen mainScreen].bounds.size.width,
                                                               [UIScreen mainScreen].bounds.size.height)];
    dimView.backgroundColor = [UIColor blackColor];
    dimView.alpha = 0.15;
    dimView.userInteractionEnabled = NO;
    [self addSubview:dimView];
    

    It works as same as default Apple implementation.

提交回复
热议问题