Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #12 from SRandazzo/custom_border
Added ability to set custom border color and width for CMPopTipView
  • Loading branch information
chrismiles committed Apr 30, 2012
2 parents 186f49d + 5ee2912 commit a89c32e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CMPopTipView/CMPopTipView.h
Expand Up @@ -109,6 +109,8 @@ typedef enum {
id targetObject; id targetObject;
UIColor *textColor; UIColor *textColor;
UIFont *textFont; UIFont *textFont;
UIColor *borderColor;
CGFloat borderWidth;
CMPopTipAnimation animation; CMPopTipAnimation animation;


@private @private
Expand All @@ -131,6 +133,8 @@ typedef enum {
@property (nonatomic, retain) UIColor *textColor; @property (nonatomic, retain) UIColor *textColor;
@property (nonatomic, retain) UIFont *textFont; @property (nonatomic, retain) UIFont *textFont;
@property (nonatomic, assign) UITextAlignment textAlignment; @property (nonatomic, assign) UITextAlignment textAlignment;
@property (nonatomic, retain) UIColor *borderColor;
@property (nonatomic, assign) CGFloat borderWidth;
@property (nonatomic, assign) CMPopTipAnimation animation; @property (nonatomic, assign) CMPopTipAnimation animation;
@property (nonatomic, assign) CGFloat maxWidth; @property (nonatomic, assign) CGFloat maxWidth;


Expand Down
30 changes: 26 additions & 4 deletions CMPopTipView/CMPopTipView.m
Expand Up @@ -40,6 +40,8 @@ @implementation CMPopTipView
@synthesize textColor; @synthesize textColor;
@synthesize textFont; @synthesize textFont;
@synthesize textAlignment; @synthesize textAlignment;
@synthesize borderColor;
@synthesize borderWidth;
@synthesize animation; @synthesize animation;
@synthesize maxWidth; @synthesize maxWidth;
@synthesize disableTapToDismiss; @synthesize disableTapToDismiss;
Expand Down Expand Up @@ -77,9 +79,9 @@ - (void)drawRect:(CGRect)rect {
CGRect bubbleRect = [self bubbleFrame]; CGRect bubbleRect = [self bubbleFrame];


CGContextRef c = UIGraphicsGetCurrentContext(); CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(c, 0.0, 0.0, 0.0, 1.0); // black CGContextSetRGBStrokeColor(c, 0.0, 0.0, 0.0, 1.0); // black
CGContextSetLineWidth(c, 1.0); CGContextSetLineWidth(c, borderWidth);


CGMutablePathRef bubblePath = CGPathCreateMutable(); CGMutablePathRef bubblePath = CGPathCreateMutable();


Expand Down Expand Up @@ -194,7 +196,24 @@ - (void)drawRect:(CGRect)rect {
CGGradientRelease(myGradient); CGGradientRelease(myGradient);
CGColorSpaceRelease(myColorSpace); CGColorSpaceRelease(myColorSpace);


CGContextSetRGBStrokeColor(c, 0.4, 0.4, 0.4, 1.0); //Draw Border
int numBorderComponents = CGColorGetNumberOfComponents([borderColor CGColor]);
const CGFloat *borderComponents = CGColorGetComponents(borderColor.CGColor);
CGFloat r, g, b, a;
if (numBorderComponents == 2) {
r = borderComponents[0];
g = borderComponents[0];
b = borderComponents[0];
a = borderComponents[1];
}
else {
r = borderComponents[0];
g = borderComponents[1];
b = borderComponents[2];
a = borderComponents[3];
}

CGContextSetRGBStrokeColor(c, r, g, b, a);
CGContextAddPath(c, bubblePath); CGContextAddPath(c, bubblePath);
CGContextDrawPath(c, kCGPathStroke); CGContextDrawPath(c, kCGPathStroke);


Expand Down Expand Up @@ -464,11 +483,13 @@ - (id)initWithFrame:(CGRect)frame {
topMargin = 2.0; topMargin = 2.0;
pointerSize = 12.0; pointerSize = 12.0;
sidePadding = 2.0; sidePadding = 2.0;
borderWidth = 1.0;


self.textFont = [UIFont boldSystemFontOfSize:14.0]; self.textFont = [UIFont boldSystemFontOfSize:14.0];
self.textColor = [UIColor whiteColor]; self.textColor = [UIColor whiteColor];
self.textAlignment = UITextAlignmentCenter; self.textAlignment = UITextAlignmentCenter;
self.backgroundColor = [UIColor colorWithRed:62.0/255.0 green:60.0/255.0 blue:154.0/255.0 alpha:1.0]; self.backgroundColor = [UIColor colorWithRed:62.0/255.0 green:60.0/255.0 blue:154.0/255.0 alpha:1.0];
self.borderColor = [UIColor blackColor];
self.animation = CMPopTipAnimationSlide; self.animation = CMPopTipAnimationSlide;
} }
return self; return self;
Expand Down Expand Up @@ -499,6 +520,7 @@ - (id)initWithCustomView:(UIView *)aView {


- (void)dealloc { - (void)dealloc {
[backgroundColor release]; [backgroundColor release];
[borderColor release];
[customView release]; [customView release];
[message release]; [message release];
[targetObject release]; [targetObject release];
Expand Down

0 comments on commit a89c32e

Please sign in to comment.