-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
…an add links directly to the NSAttributedString. This method is now preferred instead of calling addCustomLink:inRange: on the OHAttributedLabel.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,8 @@ | |
#define MRC_AUTORELEASE(x) [(x) autorelease] | ||
#endif | ||
|
||
NSString* kOHLinkAttributeName = @"NSLinkAttributeName"; // Use the same value as OSX, to be compatible in case Apple port this to iOS one day too | ||
|
||
///////////////////////////////////////////////////////////////////////////////////// | ||
#pragma mark - NSAttributedString Additions | ||
|
||
|
@@ -130,6 +132,12 @@ -(CTLineBreakMode)lineBreakModeAtIndex:(NSUInteger)index effectiveRange:(NSRange | |
CTParagraphStyleGetValueForSpecifier(style, kCTParagraphStyleSpecifierLineBreakMode, sizeof(CTLineBreakMode), &lineBreakMode); | ||
return lineBreakMode; | ||
} | ||
|
||
-(NSURL*)linkAtIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange | ||
{ | ||
return [self attribute:kOHLinkAttributeName atIndex:index effectiveRange:aRange]; | ||
} | ||
|
||
@end | ||
|
||
|
||
|
@@ -265,6 +273,15 @@ -(void)setTextAlignment:(CTTextAlignment)alignment lineBreakMode:(CTLineBreakMod | |
CFRelease(aStyle); | ||
} | ||
|
||
-(void)setLink:(NSURL*)link range:(NSRange)range | ||
{ | ||
[self removeAttribute:kOHLinkAttributeName range:range]; // Work around for Apple leak | ||
if (link) | ||
{ | ||
[self addAttribute:kOHLinkAttributeName value:(BRIDGE_CAST id)link range:range]; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
AliSoftware
Author
Owner
|
||
} | ||
} | ||
|
||
@end | ||
|
||
|
1 comment
on commit 78b2ff4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lazy question here, but does anyone know if you can store the NSAttributedString to Core Data and retain the links?
for some reason, this line yields error in my code: ".../OHAttributedLabel/OHAttributedLabel/Source/NSAttributedString+Attributes.m:281:55: Incompatible types casting 'NSURL *' to 'id' with a __bridge cast"
do you what could be possible reasons?