Skip to content

Instantly share code, notes, and snippets.

@andrewkolesnikov
Created December 17, 2011 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewkolesnikov/1489041 to your computer and use it in GitHub Desktop.
Save andrewkolesnikov/1489041 to your computer and use it in GitHub Desktop.
NeroPopoverBackgroundView
//
// NeroPopoverBackgroundView.m
// poc
//
// Created by Andrew Kolesnikov on 11/22/11.
// Copyright (c) 2011 Isobar. All rights reserved.
//
#import "NeroPopoverBackgroundView.h"
@implementation NeroPopoverBackgroundView
@synthesize arrowOffset, arrowDirection;
-(id)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
_imageView = [[[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"bg-popover.png"] resizableImageWithCapInsets: UIEdgeInsetsMake(40.0, 10.0, 30.0, 10.0)]] autorelease];
_arrowView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg-popover-arrow.png"]] autorelease];
self.backgroundColor = _arrowView.backgroundColor = _imageView.backgroundColor = [UIColor clearColor];
[self addSubview:_imageView];
[self addSubview:_arrowView];
}
return self;
}
- (void)drawRect:(CGRect)rect {
}
-(void)layoutSubviews{
if (arrowDirection == UIPopoverArrowDirectionUp) {
_imageView.frame = CGRectMake(0, [NeroPopoverBackgroundView arrowHeight], self.superview.frame.size.width, self.superview.frame.size.height - [NeroPopoverBackgroundView arrowHeight]);
_arrowView.frame = CGRectMake(self.superview.frame.size.width / 2 + arrowOffset - [NeroPopoverBackgroundView arrowBase] / 2, 2, [NeroPopoverBackgroundView arrowBase], [NeroPopoverBackgroundView arrowHeight]);
}
if (arrowDirection == UIPopoverArrowDirectionRight) {
_imageView.frame = CGRectMake(0, 0, self.superview.frame.size.width - [NeroPopoverBackgroundView arrowHeight], self.superview.frame.size.height);
_arrowView.image = [[UIImage alloc] initWithCGImage: _arrowView.image.CGImage
scale: 1.0
orientation: UIImageOrientationRight];
_arrowView.frame = CGRectMake(self.superview.frame.size.width - [NeroPopoverBackgroundView arrowHeight] - 1, self.superview.frame.size.height / 2 + arrowOffset - [NeroPopoverBackgroundView arrowBase] / 2, [NeroPopoverBackgroundView arrowHeight], [NeroPopoverBackgroundView arrowBase]);
}
}
+(UIEdgeInsets)contentViewInsets{
return UIEdgeInsetsMake(5, 5, 5, 5);
}
+(CGFloat)arrowHeight{
return 21.0;
}
+(CGFloat)arrowBase{
return 35.0;
}
@end
@akishnani
Copy link

just for reference/example , is it possible for you to post a copy of the bg-popover.png and bg-popover-arrow.png ? thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment