Created
December 17, 2011 03:27
-
-
Save andrewkolesnikov/1489041 to your computer and use it in GitHub Desktop.
NeroPopoverBackgroundView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
akishnani: http://blog.andrewkolesnikov.com/custom-background-color-tint-for-uipopover-64835