Skip to content

Instantly share code, notes, and snippets.

@mojeld
Last active August 29, 2015 14:25
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 mojeld/ccd46a069f4e27619725 to your computer and use it in GitHub Desktop.
Save mojeld/ccd46a069f4e27619725 to your computer and use it in GitHub Desktop.
"NSTextView" NSString, append it with a NSColor
//NSTextView 文字に色を付けてAppendする。
//Xcode6.3 MacOS
-(void)Append2:(NSString*)value1 lov:(NSTextView *)lov color:(NSColor*)cl
{
//dispatch_asyncブロック渡しする為?
dispatch_async(
//dispatch_get_main_queueメインのキューで処理
dispatch_get_main_queue(), ^{//^マークはブロック型(クロージャー)と言う事らしいです。
//↓attributeの入れ物を作る。
NSDictionary *satt = @{ NSForegroundColorAttributeName : cl};
//textStorageに追記する場合はNSAttributedStringを使う。
NSAttributedString* attr = [[NSAttributedString alloc] initWithString:value1 attributes:satt];
//NSTextViewにAppendする。
[[lov textStorage] appendAttributedString:attr];
[lov scrollRangeToVisible:NSMakeRange([[lov string] length], 0)];
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment