Skip to content
Browse files

implemented setting a hyperlink active color

Either specify a color in the parsing options with DTDefaultLinkHighlightColor (text or color) or specify a:active in stylesheet.
  • Loading branch information...
1 parent 841a950 commit 7224445b10aef365f58153613b7dc9e66f22c3b0 @odrobnik odrobnik committed Mar 21, 2013
View
1 Core/Source/DTCoreTextConstants.h
@@ -43,6 +43,7 @@ extern NSString * const DTDefaultFontSize;
extern NSString * const DTDefaultTextColor;
extern NSString * const DTDefaultLinkColor;
extern NSString * const DTDefaultLinkDecoration;
+extern NSString * const DTDefaultLinkHighlightColor;
extern NSString * const DTDefaultTextAlignment;
extern NSString * const DTDefaultLineHeightMultiplier;
extern NSString * const DTDefaultLineHeightMultiplier;
View
2 Core/Source/DTCoreTextConstants.m
@@ -16,7 +16,7 @@
NSString * const DTDefaultFontSize = @"DTDefaultFontSize";
NSString * const DTDefaultTextColor = @"DTDefaultTextColor";
NSString * const DTDefaultLinkColor = @"DTDefaultLinkColor";
-//NSString * const DTDefaultLinkHighlightColor = @"DTDefaultLinkHighlightColor";
+NSString * const DTDefaultLinkHighlightColor = @"DTDefaultLinkHighlightColor";
NSString * const DTDefaultLinkDecoration = @"DTDefaultLinkDecoration";
NSString * const DTDefaultTextAlignment = @"DTDefaultTextAlignment";
NSString * const DTDefaultLineHeightMultiplier = @"DTDefaultLineHeightMultiplier";
View
1 Core/Source/DTHTMLAttributedStringBuilder.h
@@ -33,6 +33,7 @@ typedef void(^DTHTMLAttributedStringBuilderWillFlushCallback)(DTHTMLElement *);
- DTDefaultTextColor: the default text color
- DTDefaultLinkColor: the default color for hyperlink text
- DTDefaultLinkDecoration: the default decoration for hyperlinks
+ - DTDefaultLinkHighlightColor: the color to show while the hyperlink is highlighted
- DTDefaultTextAlignment: the default text alignment for paragraphs
- DTDefaultLineHeightMultiplier: The multiplier for line heights
- DTDefaultFirstLineHeadIndent: The default indent for left margin on first line
View
18 Core/Source/DTHTMLAttributedStringBuilder.m
@@ -225,6 +225,24 @@ - (BOOL)_buildString
}
}
+ DTColor *defaultLinkHighlightColor = [_options objectForKey:DTDefaultLinkHighlightColor];
+
+ if (defaultLinkHighlightColor)
+ {
+ if ([defaultLinkHighlightColor isKindOfClass:[NSString class]])
+ {
+ // convert from string to color
+ defaultLinkHighlightColor = [DTColor colorWithHTMLName:(NSString *)defaultLinkHighlightColor];
+ }
+
+ // get hex code for the passed color
+ NSString *colorHex = [defaultLinkHighlightColor htmlHexString];
+
+ // overwrite the style
+ NSString *styleBlock = [NSString stringWithFormat:@"a:active {color:#%@;}", colorHex];
+ [_globalStyleSheet parseStyleBlock:styleBlock];
+ }
+
// default paragraph style
_defaultParagraphStyle = [DTCoreTextParagraphStyle defaultParagraphStyle];
View
10 Core/Source/DTHTMLElementA.m
@@ -7,6 +7,7 @@
//
#import "DTHTMLElementA.h"
+#import "DTColor+HTML.h"
@implementation DTHTMLElementA
{
@@ -17,8 +18,13 @@ - (void)applyStyleDictionary:(NSDictionary *)styles
{
[super applyStyleDictionary:styles];
- // TODO: get the highlighted color from CSS
- self.highlightedTextColor = [DTColor redColor];
+ // get highlight color from a:active pseudo-selector
+ NSString *activeColor = [styles objectForKey:@"active:color"];
+
+ if (activeColor)
+ {
+ self.highlightedTextColor = [DTColor colorWithHTMLName:activeColor];
+ }
}
- (NSAttributedString *)attributedString
View
2 Core/Source/default.css
@@ -105,6 +105,8 @@ a
text-decoration:underline;
}
+a:active {color:#FF0000;} /* link while finger down */
+
center
{
text-align:center;
View
11 Demo/Resources/CurrentTest.html
@@ -1,10 +1,11 @@
<!-- shows different unline position in a hyperlink that has a part with superscript text -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html40/strict.dtd">
<html>
- <p style="font-family:'Times New Roman';font-size:50px">50px: <u>Underlining</u></p>
- <p style="font-family:'Times New Roman';font-size:40px">40px: <u>Underlining</u></p>
- <p style="font-family:'Times New Roman';font-size:30px">30px: <u>Underlining</u></p>
- <p style="font-family:'Times New Roman';font-size:20px">20px: <u>Underlining</u></p>
- <p style="font-family:'Times New Roman';font-size:10px">10px: <u>Underlining</u></p>
+ <head>
+ <style>
+ a:active {color:#0000FF;} /* selected link */
+ </style>
+ <body ontouchstart="">
+ <p style="font-family:'Times New Roman';font-size:50px">Some normal <u>unde</u> <a href="http://apple.com">U</a> and onwards</p>
</body>
</html>
View
2 Demo/Source/DemoTextViewController.m
@@ -154,7 +154,7 @@ - (NSAttributedString *)_attributedStringForSnippetUsingiOS6Attributes:(BOOL)use
};
NSMutableDictionary *options = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:1.0], NSTextSizeMultiplierDocumentOption, [NSValue valueWithCGSize:maxImageSize], DTMaxImageSize,
- @"Times New Roman", DTDefaultFontFamily, @"purple", DTDefaultLinkColor, callBackBlock, DTWillFlushBlockCallBack, nil];
+ @"Times New Roman", DTDefaultFontFamily, @"purple", DTDefaultLinkColor, @"red", DTDefaultLinkHighlightColor, callBackBlock, DTWillFlushBlockCallBack, nil];
if (useiOS6Attributes)
{

0 comments on commit 7224445

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