我使用了这个好的教程来创建一个定制的UIPopoverBackgroundView类。
效果很好。唯一的问题是,我没有得到典型的UIPopoverController下降阴影,我想要它。我尝试在我的UIPopoverBackgroundView实例的层上指定它,但没有成功。我的UIPopoverController实例似乎没有一个可以操作的公共视图。将其添加到popover内容也不起作用。
可能非常简单:如何在使用自定义UIPopoverBackgroundView类时添加下拉阴影?
// UIPopoverBackoundView.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,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;
}发布于 2012-04-06 13:55:48
好吧,想清楚了。我需要向borderImageView添加拖放阴影,而不是popover实例的视图。
- (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,CAP_INSET)]];
_arrowView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg-popover-arrow.png"]];
[self addSubview:_borderImageView];
[self addSubview:_arrowView];
_borderImageView.layer.cornerRadius = 5.0f;
_borderImageView.layer.masksToBounds = NO;
_borderImageView.layer.borderWidth = 1.0f;
_borderImageView.layer.borderColor = [UIColor blackColor].CGColor;
_borderImageView.layer.shadowColor = [UIColor blackColor].CGColor;
_borderImageView.layer.shadowOpacity = 0.8;
_borderImageView.layer.shadowRadius = 50;
_borderImageView.layer.shadowOffset = CGSizeMake(-10.0f, 10.0f);
}
return self;
}发布于 2012-10-02 04:41:26
你不需要添加你自己的影子。基础UIPopoverBackgroundView会为你做这件事。只需确保在您的layoutSubviews实现中调用超级。
编辑:我的评论适用于针对iOS 6的应用程序。
https://stackoverflow.com/questions/10044227
复制相似问题