Skip to content
This repository has been archived by the owner on Feb 7, 2020. It is now read-only.

Commit

Permalink
fix case when setting custom attributes for hot words
Browse files Browse the repository at this point in the history
refactor when adding default attributes
  • Loading branch information
nandodelauni committed Sep 8, 2015
1 parent a0fd456 commit eb8cd45
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions STTweetLabel/STTweetLabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -318,20 +318,9 @@ - (void)setValidProtocols:(NSArray *)validProtocols {
[self determineHotWords];
}

- (void)setAttributes:(NSDictionary *)attributes {
if (!attributes[NSFontAttributeName]) {
NSMutableDictionary *copy = [attributes mutableCopy];
copy[NSFontAttributeName] = self.font;
attributes = [NSDictionary dictionaryWithDictionary:copy];
}

if (!attributes[NSForegroundColorAttributeName]) {
NSMutableDictionary *copy = [attributes mutableCopy];
copy[NSForegroundColorAttributeName] = self.textColor;
attributes = [NSDictionary dictionaryWithDictionary:copy];
}

_attributesText = attributes;
- (void)setAttributes:(NSDictionary *)attributes
{
_attributesText = [self addDefaultAttributes:attributes];

[self determineHotWords];
}
Expand Down Expand Up @@ -359,19 +348,21 @@ - (void)setAttributes:(NSDictionary *)attributes hotWord:(STTweetHotWord)hotWord

- (NSDictionary *)addDefaultAttributes:(NSDictionary *)attributes
{
if (!attributes[NSFontAttributeName]) {
NSMutableDictionary *copy = [attributes mutableCopy];
copy[NSFontAttributeName] = self.font;
attributes = [NSDictionary dictionaryWithDictionary:copy];
}
NSMutableDictionary *allAttributes = [attributes mutableCopy];

if (!attributes[NSFontAttributeName])
allAttributes[NSFontAttributeName] = self.font;

if (!attributes[NSForegroundColorAttributeName])
allAttributes[NSForegroundColorAttributeName] = self.textColor;

if (!attributes[NSForegroundColorAttributeName]) {
NSMutableDictionary *copy = [attributes mutableCopy];
copy[NSForegroundColorAttributeName] = self.textColor;
attributes = [NSDictionary dictionaryWithDictionary:copy];
if (!attributes[NSParagraphStyleAttributeName]) {
NSMutableParagraphStyle *newParagraphStyle = [[NSMutableParagraphStyle alloc] init];
[newParagraphStyle setAlignment:self.textAlignment];
allAttributes[NSParagraphStyleAttributeName] = newParagraphStyle;
}

return attributes;
return [allAttributes copy];
}

- (void)setAttributes:(NSDictionary *)attributes forCustomString:(NSString *)string
Expand Down

0 comments on commit eb8cd45

Please sign in to comment.