Skip to content
Browse files

Merge pull request #12 from SRandazzo/custom_border

Added ability to set custom border color and width for CMPopTipView
  • Loading branch information...
2 parents 186f49d + 5ee2912 commit a89c32e3bfb0d3b58c3eb66c9d503f00ec290b7c @chrismiles committed
Showing with 30 additions and 4 deletions.
  1. +4 −0 CMPopTipView/CMPopTipView.h
  2. +26 −4 CMPopTipView/CMPopTipView.m
View
4 CMPopTipView/CMPopTipView.h
@@ -109,6 +109,8 @@ typedef enum {
id targetObject;
UIColor *textColor;
UIFont *textFont;
+ UIColor *borderColor;
+ CGFloat borderWidth;
CMPopTipAnimation animation;
@private
@@ -131,6 +133,8 @@ typedef enum {
@property (nonatomic, retain) UIColor *textColor;
@property (nonatomic, retain) UIFont *textFont;
@property (nonatomic, assign) UITextAlignment textAlignment;
+@property (nonatomic, retain) UIColor *borderColor;
+@property (nonatomic, assign) CGFloat borderWidth;
@property (nonatomic, assign) CMPopTipAnimation animation;
@property (nonatomic, assign) CGFloat maxWidth;
View
30 CMPopTipView/CMPopTipView.m
@@ -40,6 +40,8 @@ @implementation CMPopTipView
@synthesize textColor;
@synthesize textFont;
@synthesize textAlignment;
+@synthesize borderColor;
+@synthesize borderWidth;
@synthesize animation;
@synthesize maxWidth;
@synthesize disableTapToDismiss;
@@ -77,9 +79,9 @@ - (void)drawRect:(CGRect)rect {
CGRect bubbleRect = [self bubbleFrame];
CGContextRef c = UIGraphicsGetCurrentContext();
-
- CGContextSetRGBStrokeColor(c, 0.0, 0.0, 0.0, 1.0); // black
- CGContextSetLineWidth(c, 1.0);
+
+ CGContextSetRGBStrokeColor(c, 0.0, 0.0, 0.0, 1.0); // black
+ CGContextSetLineWidth(c, borderWidth);
CGMutablePathRef bubblePath = CGPathCreateMutable();
@@ -194,7 +196,24 @@ - (void)drawRect:(CGRect)rect {
CGGradientRelease(myGradient);
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);
CGContextDrawPath(c, kCGPathStroke);
@@ -464,11 +483,13 @@ - (id)initWithFrame:(CGRect)frame {
topMargin = 2.0;
pointerSize = 12.0;
sidePadding = 2.0;
+ borderWidth = 1.0;
self.textFont = [UIFont boldSystemFontOfSize:14.0];
self.textColor = [UIColor whiteColor];
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.borderColor = [UIColor blackColor];
self.animation = CMPopTipAnimationSlide;
}
return self;
@@ -499,6 +520,7 @@ - (id)initWithCustomView:(UIView *)aView {
- (void)dealloc {
[backgroundColor release];
+ [borderColor release];
[customView release];
[message release];
[targetObject release];

0 comments on commit a89c32e

Please sign in to comment.
Something went wrong with that request. Please try again.