Last active
August 29, 2015 14:25
-
-
Save mojeld/ccd46a069f4e27619725 to your computer and use it in GitHub Desktop.
"NSTextView" NSString, append it with a NSColor
This file contains 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
//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