static NSAttributedString *placeHolderString;@implementation TextVIEwWithPlaceHolder+(voID)initialize{ static BOol initialized = NO; if (!initialized){ NScolor *txtcolor = [NScolor graycolor]; NSDictionary *txtDict = [NSDictionary dictionaryWithObjectsAndKeys:txtcolor,NSForegroundcolorAttributename,nil]; placeHolderString = [[NSAttributedString alloc] initWithString:@"This is my placeholder text" attributes:txtDict]; }}- (BOol)becomeFirstResponder{ [self setNeedsdisplay:YES]; return [super becomeFirstResponder];}- (voID)drawRect:(NSRect)rect{ [super drawRect:rect]; if ([[self string] isEqualToString:@""] && self != [[self window] firstResponder]) [placeHolderString drawAtPoint:NSMakePoint(0,0)];}- (BOol)resignFirstResponder{ [self setNeedsdisplay:YES]; return [super resignFirstResponder];}@end总结
以上是内存溢出为你收集整理的macos – 为NSTextView设置占位符字符串全部内容,希望文章能够帮你解决macos – 为NSTextView设置占位符字符串所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)