Last active
December 18, 2015 16:18
-
-
Save vendruscolo/5809924 to your computer and use it in GitHub Desktop.
Poor's man fix for this issue https://github.com/mattt/TTTAttributedLabel/issues/240
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)setTextAlignment:(NSTextAlignment)textAlignment { | |
NSTextAlignment oldTextAlignment = self.textAlignment; | |
[super setTextAlignment:textAlignment]; | |
if (textAlignment != oldTextAlignment) { | |
// update link attributes | |
if (self.linkAttributes) { | |
NSMutableDictionary *mutableLinkAttributes = [self.linkAttributes mutableCopy]; | |
NSMutableDictionary *mutableActiveLinkAttributes = [self.activeLinkAttributes mutableCopy]; | |
if ([NSMutableParagraphStyle class]) { | |
NSMutableParagraphStyle *paragraphStyle = [[mutableLinkAttributes objectForKey:(NSString *)kCTParagraphStyleAttributeName] mutableCopy]; | |
paragraphStyle.alignment = textAlignment; | |
[mutableLinkAttributes setObject:paragraphStyle forKey:(NSString *)kCTParagraphStyleAttributeName]; | |
[mutableActiveLinkAttributes setObject:paragraphStyle forKey:(NSString *)kCTParagraphStyleAttributeName]; | |
} else { | |
CTTextAlignment ctTextAlignment = CTTextAlignmentFromUITextAlignment(textAlignment); | |
CTParagraphStyleSetting paragraphStyles[1] = { | |
{.spec = kCTParagraphStyleSpecifierAlignment, .valueSize = sizeof(CTTextAlignment), .value = (const void *)&ctTextAlignment} | |
}; | |
CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(paragraphStyles, 1); | |
// am I overwriting old settings? | |
[mutableLinkAttributes setObject:(__bridge id)paragraphStyle forKey:(NSString *)kCTParagraphStyleAttributeName]; | |
[mutableLinkAttributes setObject:(__bridge id)paragraphStyle forKey:(NSString *)kCTParagraphStyleAttributeName]; | |
CFRelease(paragraphStyle); | |
} | |
self.linkAttributes = [NSDictionary dictionaryWithDictionary:mutableLinkAttributes]; | |
self.activeLinkAttributes = [NSDictionary dictionaryWithDictionary:mutableActiveLinkAttributes]; | |
} | |
[self setNeedsFramesetter]; | |
[self setNeedsDisplay]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment