NSTextField 简介
输入框,主要用于用户输入文本,同 iOS里的UITextField
在macOS开发环境下,没有像iOS里的UILabel一样定义、创建标签,此时可以使用NSTextField创建标签
NSTextField 举例
- (void)viewDidLoad {     [super viewDidLoad];
      NSTextField *tf = [[NSTextField alloc] initWithFrame:CGRectMake(0, 0, 500, 100)];     tf.toolTip = @"10月16日,第二届中国互联网企业社会责任高峰论坛暨《2020中国互联网企业社会责任报告》(下称“报告”)发布会在京举办。";     NSString *text = @"10月16日,第二届中国互联网企业社会责任高峰论坛暨《2020中国互联网企业社会责任报告》(下称“报告”)发布会在京举办。报告由北京师范大学互联网发展研究院、互联网司法治理研究中心联合光明网、中国经济网、中国日报网、中国网、北师大中国教育与社会发展研究院权威发布,系统评价了中国互联网企业社会责任发展现状,为进一步强化社会责任意识,改进社会责任管理,更好地促进经济效益与社会效益的统一,实现企业和行业健康、有序地发展提供依据。";          NSDictionary *middleAttributeDic = @{NSStrikethroughStyleAttributeName : @(NSUnderlineStyleSingle)};     
 
 
      NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:text attributes:middleAttributeDic];          tf.attributedStringValue = attributeStr;     tf.placeholderString = @"NSTextField-placeholdString";     tf.backgroundColor = NSColor.clearColor;     tf.textColor = NSColor.whiteColor;     tf.bordered = false;     tf.editable = false;     tf.selectable = true;     tf.highlighted = false; 	  tf.focusRingType = NSFocusRingTypeNone;     tf.delegate = self;     [[tf cell] setUsesSingleLineMode:false];     [[tf cell] setTruncatesLastVisibleLine:false];     tf.font = [NSFont systemFontOfSize:15];     tf.alignment = NSTextAlignmentCenter;     tf.maximumNumberOfLines = 2;     [self.view addSubview:tf]; }
  #pragma mark - NSTextFieldDelegate
  - (BOOL)textField:(NSTextField *)textField textView:(NSTextView *)textView shouldSelectCandidateAtIndex:(NSUInteger)index {     return YES; }
  - (NSArray *)textField:(NSTextField *)textField textView:(NSTextView *)textView candidatesForSelectedRange:(NSRange)selectedRange {     return @[]; }
  - (NSArray<NSTextCheckingResult *> *)textField:(NSTextField *)textField textView:(NSTextView *)textView candidates:(NSArray<NSTextCheckingResult *> *)candidates forSelectedRange:(NSRange)selectedRange {     return @[]; }```
 
  |