Browse files

Added option to disable highlight rectangle

  • Loading branch information...
1 parent 44d7179 commit ba229fe7f5b4b613ff3fe50bc4f23968b2b970fe @odrobnik odrobnik committed Aug 29, 2012
Showing with 16 additions and 4 deletions.
  1. +5 −0 Core/Source/DTLinkButton.h
  2. +11 −4 Core/Source/DTLinkButton.m
View
5 Core/Source/DTLinkButton.h
@@ -39,6 +39,11 @@ extern NSString *DTLinkButtonDidHighlightNotification;
/**
+ A Boolean value that determines whether tapping the button causes it to show a gray rounded rectangle. Default is YES.
+ */
+@property(nonatomic) BOOL showsTouchWhenHighlighted;
+
+/**
The attributed string to be drawn for the link button.
*/
@property (nonatomic, retain) NSAttributedString *attributedString;
View
15 Core/Source/DTLinkButton.m
@@ -32,6 +32,7 @@ @implementation DTLinkButton
NSString *_GUID;
CGSize _minimumHitSize;
+ BOOL _showsTouchWhenHighlighted;
// normal text
NSAttributedString *_attributedString;
@@ -53,6 +54,8 @@ - (id)initWithFrame:(CGRect)frame
self.enabled = YES;
self.opaque = NO;
+ _showsTouchWhenHighlighted = YES;
+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(highlightNotification:) name:DTLinkButtonDidHighlightNotification object:nil];
}
@@ -244,11 +247,14 @@ - (void)drawRect:(CGRect)rect
{
[self drawTextInContext:ctx highlighted:YES];
- CGRect imageRect = [self contentRectForBounds:self.bounds];
+ if (_showsTouchWhenHighlighted)
+ {
+ CGRect imageRect = [self contentRectForBounds:self.bounds];
- UIBezierPath *roundedPath = [UIBezierPath bezierPathWithRoundedRect:imageRect cornerRadius:3.0f];
- CGContextSetGrayFillColor(ctx, 0.73f, 0.4f);
- [roundedPath fill];
+ UIBezierPath *roundedPath = [UIBezierPath bezierPathWithRoundedRect:imageRect cornerRadius:3.0f];
+ CGContextSetGrayFillColor(ctx, 0.73f, 0.4f);
+ [roundedPath fill];
+ }
}
else
{
@@ -356,6 +362,7 @@ - (void)setMinimumHitSize:(CGSize)minimumHitSize
@synthesize GUID = _GUID;
@synthesize minimumHitSize = _minimumHitSize;
+@synthesize showsTouchWhenHighlighted = _showsTouchWhenHighlighted;
@synthesize attributedString = _attributedString;
@synthesize highlightedAttributedString = _highlightedAttributedString;

0 comments on commit ba229fe

Please sign in to comment.