我已经按如下方式实现了这个类:
#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:。添加后它可以工作。苹果的错误信息只是乱码。