我已经按如下方式实现了这个类:
#import "JKBackgroundView.h"
@implementation JKBackgroundView
static CGFloat jkArrowBase = 26.0;
static CGFloat jkArrowHeight = 16.0;
// Background image insets
static CGFloat jkBackgroundTopInset = 68.0f;
static CGFloat jkBackgroundLeftInset = 16.0f;
static CGFloat jkBackgroundBottomInset = 16.0f;
static CGFloat jkBackgroundRightInset = 34.0f;
// Content view insets
static CGFloat jkContentTopInset = 40.0f;
static CGFloat jkContentLeftInset = 6.0f;
static CGFloat jkContentBottomInset = 8.0f;
static CGFloat jkContentRightInset = 7.0f;
+(CGFloat)arrowBase {
return jkArrowBase;
}
-(UIPopoverArrowDirection)arrowDirection {
return UIPopoverArrowDirectionUp;
}
-(CGFloat)arrowOffset {
return 0.0f;
}
+(CGFloat)arrowHeight {
return jkArrowHeight;
}
+(UIEdgeInsets)contentViewInsets {
return UIEdgeInsetsMake(jkContentTopInset, jkContentLeftInset, jkContentBottomInset, jkContentRightInset);
}
-(void)drawRect:(CGRect)rect {
UIEdgeInsets popoverInsets = UIEdgeInsetsMake(jkBackgroundTopInset, jkBackgroundLeftInset, jkBackgroundBottomInset, jkBackgroundRightInset);
UIImage *popoverImage = [[UIImage imageNamed:@"popover_stretchable.png"] resizableImageWithCapInsets:popoverInsets];
[popoverImage drawInRect:rect];
}
-(id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
}
return self;
}
-(void)setArrowDirection:(UIPopoverArrowDirection)arrowDirection {
// Do nothing
}
@end
我使用以下代码将其添加到我的UIPopoverView(不是子类):
_logoutPopover.popoverBackgroundViewClass = [JKBackgroundView class];
但是,当我运行该项目时,我收到如下疯狂的错误消息:
* 由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:' - [UIPopoverBackgroundView ¯¯lå]必须由子类实现。'
有谁知道它认为我没有实施的方法是什么?它似乎只是一堆胡言乱语。谢谢!
编辑看起来我忘了实施setArrowOffset:。添加后它可以工作。 Apple的错误信息只是乱码。
答案 0 :(得分:3)
根据docs for UIPopoverBackgroundView,您还需要为UIPopoverBackgroundView
(即arrowDirection
和arrowOffset
中的属性实施设置器。)您刚刚获得了getter你的实施。