Skip to content

Instantly share code, notes, and snippets.

@tomohisa
Created December 6, 2013 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomohisa/7818580 to your computer and use it in GitHub Desktop.
Save tomohisa/7818580 to your computer and use it in GitHub Desktop.
NSMutableAttributedString * mutable = [[NSMutableAttributedString alloc] init];
[mutable appendAttributedString:[[NSMutableAttributedString alloc] initWithString:self.user.name attributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:12*TOVConstSizeRate]}]];
[mutable appendAttributedString:[[NSMutableAttributedString alloc] initWithString:@" " attributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:6*TOVConstSizeRate]}]];
[mutable appendAttributedString:[[NSMutableAttributedString alloc] initWithString:@"(@" attributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:11*TOVConstSizeRate]}]];
[mutable appendAttributedString:[[NSMutableAttributedString alloc] initWithString:self.user.screenName attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:11*TOVConstSizeRate]}]];
[mutable appendAttributedString:[[NSMutableAttributedString alloc] initWithString:@")\t" attributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:11*TOVConstSizeRate]}]];
[mutable appendAttributedString:[[NSMutableAttributedString alloc] initWithString:[CommonDate getFlexibleDateStringFromDate:self.createdAt] attributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:11*TOVConstSizeRate]}]];
[mutable appendAttributedString:[[NSMutableAttributedString alloc] initWithString:@"\n" attributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:11*TOVConstSizeRate]}]];
[mutable appendAttributedString:[[NSMutableAttributedString alloc] initWithString:[self.text stringByDecodingHTMLEntities] attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12*TOVConstSizeRate]}]];
if (self.retweetersStatus) {
[mutable appendAttributedString:[[NSMutableAttributedString alloc] initWithString:@"\nretweeted by:" attributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:10*TOVConstSizeRate]}]];
[mutable appendAttributedString:[[NSMutableAttributedString alloc] initWithString:self.retweetersStatus.user.name attributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:11*TOVConstSizeRate]}]];
[mutable appendAttributedString:[[NSMutableAttributedString alloc] initWithString:@" " attributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:6*TOVConstSizeRate]}]];
[mutable appendAttributedString:[[NSMutableAttributedString alloc] initWithString:@"(@" attributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:10*TOVConstSizeRate]}]];
[mutable appendAttributedString:[[NSMutableAttributedString alloc] initWithString:self.retweetersStatus.user.screenName attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:10*TOVConstSizeRate]}]];
[mutable appendAttributedString:[[NSMutableAttributedString alloc] initWithString:@")\t" attributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:10*TOVConstSizeRate]}]];
[mutable appendAttributedString:[[NSMutableAttributedString alloc] initWithString:[CommonDate getFlexibleDateStringFromDate:self.retweetersStatus.createdAt] attributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:10*TOVConstSizeRate]}]];
}
[mutable addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:TOV2Data.fontColorRed green:TOV2Data.fontColorGreen blue:TOV2Data.fontColorBlue alpha:1.0] range:NSMakeRange(0, mutable.length)];
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
paragraph.minimumLineHeight = 12.0f*TOVConstSizeRate;
paragraph.maximumLineHeight = 12.0f*TOVConstSizeRate;
paragraph.alignment = NSTextAlignmentLeft;
paragraph.lineBreakMode = NSLineBreakByCharWrapping;
NSTextTab *t = [[NSTextTab alloc] initWithTextAlignment:NSTextAlignmentRight location:width-10 options:nil];
paragraph.tabStops = @[t];
[mutable addAttribute:NSParagraphStyleAttributeName value:paragraph range:NSMakeRange(0, mutable.length)];
textView.attributedText = mutable.copy;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment