Skip to content

Commit

Permalink
fix setText crash bug
Browse files Browse the repository at this point in the history
  • Loading branch information
amir hayek committed Jun 28, 2016
1 parent aa4ec11 commit 28a5220
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

*.xcuserstate
Binary file not shown.
28 changes: 20 additions & 8 deletions UIReadMoreLabel/UIReadMoreLabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,27 @@ -(id)initWithCoder:(NSCoder *)aDecoder
-(void)setText:(NSString *)text
{
[super setText:text];

if (text == nil) {
return;
}

_isTruncated = [self checkTruncation];
if (_isTruncated) {
NSMutableAttributedString* attributedString = [[NSMutableAttributedString alloc] initWithString:self.text];
[attributedString setAttributes:@{NSFontAttributeName:self.font}
range:NSMakeRange(0, self.attributedText.length-_truncationString.length)];
[attributedString setAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:self.font.pointSize],
NSForegroundColorAttributeName:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.3]}
range:NSMakeRange(self.attributedText.length-_truncationString.length, _truncationString.length)];
[self setAttributedText:attributedString];
@try
{
if (_isTruncated) {
NSMutableAttributedString* attributedString = [[NSMutableAttributedString alloc] initWithString:self.text];
[attributedString setAttributes:@{NSFontAttributeName:self.font}
range:NSMakeRange(0, self.attributedText.length-_truncationString.length)];
[attributedString setAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:self.font.pointSize],
NSForegroundColorAttributeName:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.3]}
range:NSMakeRange(self.attributedText.length-_truncationString.length, _truncationString.length)];
[self setAttributedText:attributedString];
}
}
@catch (NSException *exception) //NSRangeException
{
return;
}
}

Expand Down

0 comments on commit 28a5220

Please sign in to comment.