Created
May 19, 2015 00:36
-
-
Save dothework/76f702a5ea166e48fdd3 to your computer and use it in GitHub Desktop.
Orange for the first comment only
This file contains hidden or 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
- (NSAttributedString *) commentString { | |
NSMutableAttributedString *commentString = [[NSMutableAttributedString alloc] init]; | |
BOOL bolFirst = YES; | |
for (Comment *comment in self.mediaItem.comments) { | |
// Make a string that says "username comment" followed by a line break | |
NSString *baseString = [NSString stringWithFormat:@"%@ %@\n", comment.from.userName, comment.text]; | |
// Make an attributed string, with the "username" bold | |
NSMutableAttributedString *oneCommentString = [[NSMutableAttributedString alloc] initWithString:baseString attributes:@{NSFontAttributeName : lightFont, NSParagraphStyleAttributeName : paragraphStyle}]; | |
NSRange usernameRange = [baseString rangeOfString:comment.from.userName]; | |
[oneCommentString addAttribute:NSFontAttributeName value:boldFont range:usernameRange]; | |
[oneCommentString addAttribute:NSForegroundColorAttributeName value:linkColor range:usernameRange]; | |
NSRange commentRange = [baseString rangeOfString:comment.text]; | |
// set the color to orange for the first comment only | |
if (bolFirst) { | |
[oneCommentString addAttribute:NSForegroundColorAttributeName value:oneCommentColor range:commentRange]; | |
bolFirst = NO; | |
} | |
else { | |
[oneCommentString addAttribute:NSForegroundColorAttributeName value:linkColor range:commentRange]; | |
} | |
[commentString appendAttributedString:oneCommentString]; | |
} | |
return commentString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment