ios – 自定义UIPopoverBackgroundView:没有阴影

我使用这个好的 tutorial来创建一个自定义的UIPopoverBackgroundView类.

它工作得很好唯一的问题是我没有得到典型的UIPopoverController下降阴影,我想要它.我尝试在我的UIPopoverBackgroundView实例的层上指定它,而不成功.我的UIPopoverController实例似乎没有公开的操作视图.将其添加到popover内容也不起作用.

可能真的很简单:如何在使用自定义UIPopoverBackgroundView类时添加阴影?

// UIPopoverBackgroundView.m

-(id)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        _borderImageView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"bg-popover.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(CAP_INSET,CAP_INSET,CAP_INSET)]];

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

        [self addSubview:_borderImageView];
        [self addSubview:_arrowView];

        self.layer.shadowOffset = CGSizeMake(50,50);
        self.layer.shadowColor = [[UIColor blackColor] CGColor];
    }

    return self;
}

解决方法

你不需要添加自己的阴影.基本的UIPopoverBackgroundView将为您做.只需确保在您的layoutSubviews实现中调用super.

编辑:我的评论适用于iOS 6的应用.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...