Để tham khảo, bạn muốn đọc mô tả kiểu đoạn này: Cocoa Paragraph Styles và lưu ý rằng mọi thứ trong đó có thêm khoảng trắng giữa các dòng, giữa các đoạn, trước đoạn văn, v.v. Bạn có thể đặt giá trị trong NSMutableParagraphStyle thành 0 nhưng không thấp hơn.
Để thu nhỏ hơn nữa khoảng cách giữa các dòng, sử dụng setMaximumLineHeight, nhờ "6 1" cho mã (Tôi đã thêm setMaximumLineHeight):
NSString *title = @"title here";
NSFont *bold14 = [NSFont boldSystemFontOfSize:14.0];
NSColor *textColor = [NSColor redColor];
NSMutableParagraphStyle *textParagraph = [[NSMutableParagraphStyle alloc] init];
[textParagraph setLineSpacing:10.0]; // this sets the space BETWEEN lines to 10points
[textParagraph setMaximumLineHeight:12.0]; this sets the MAXIMUM height of the lines to 12points
NSDictionary *attrDic = [NSDictionary dictionaryWithObjectsAndKeys:bold14, NSFontAttributeName, textColor, NSForegroundColorAttributeName, textParagraph, NSParagraphStyleAttributeName, nil];
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:title attributes:attrDic];
[self.titleField setAllowsEditingTextAttributes:YES];
[self.titleField setAttributedStringValue:attrString];
Nguồn
2014-05-12 17:38:46
Tại sao bạn không thể sử dụng NSTextView? NSTextField thường được sử dụng cho các trường văn bản dòng đơn. – sidyll