-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNSAttributedString+Hyperlink.m
More file actions
32 lines (24 loc) · 1016 Bytes
/
NSAttributedString+Hyperlink.m
File metadata and controls
32 lines (24 loc) · 1016 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//
// NSAttributedString+Hyperlink.m
// NimbusPrefs
//
// Created by Sagar Pandya on 3/21/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "NSAttributedString+Hyperlink.h"
@implementation NSAttributedString (Hyperlink)
+ (id)hyperlinkFromString:(NSString *)inString withURL:(NSURL *)aURL
{
NSMutableAttributedString* attrString = [[NSMutableAttributedString alloc] initWithString: inString];
NSRange range = NSMakeRange(0, [attrString length]);
[attrString beginEditing];
[attrString addAttribute:NSLinkAttributeName value:[aURL absoluteString] range:range];
// make the text appear in blue
[attrString addAttribute:NSForegroundColorAttributeName value:[NSColor blueColor] range:range];
// next make the text appear with an underline
[attrString addAttribute:
NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSSingleUnderlineStyle] range:range];
[attrString endEditing];
return [attrString autorelease];
}
@end