我使用这个好的
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的应用.