Skip to content

Instantly share code, notes, and snippets.

@seiji
Last active April 18, 2017 20:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save seiji/3930237 to your computer and use it in GitHub Desktop.
Save seiji/3930237 to your computer and use it in GitHub Desktop.
Append NSAttributedString
NSAttributedString *subjectString =
[[NSAttributedString alloc] initWithString:@"git"
attributes:@{
NSForegroundColorAttributeName : [UIColor blueColor],
NSFontAttributeName : [UIFont boldSystemFontOfSize:20]
}];
NSAttributedString *verbString = [[NSAttributedString alloc] initWithString:@" push -u "];
NSAttributedString *objectString =
[[NSAttributedString alloc] initWithString:@"origin master"
attributes:@{
NSForegroundColorAttributeName : [UIColor redColor],
NSFontAttributeName : [UIFont boldSystemFontOfSize:20]
}];
NSMutableAttributedString *message = [[NSMutableAttributedString alloc] initWithAttributedString:subjectString];
[message appendAttributedString:verbString];
[message appendAttributedString:objectString];
self.label.attributedText = message;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment