Native lack of display Label Label, after a period of learning, NNLabel achieved its desired effect, simple call, the effect is as follows.

typedef NS_ENUM(NSInteger, NSContentVerticalAlignment) { NSContentVerticalAlignmentTop = 0, NSContentVerticalAlignmentCenter = 1, NSContentVerticalAlignmentBottom = 2, }; @interface NNLabel : NSView @property(nullable, nonatomic,copy) NSString *text; // default is nil @property(nonatomic, strong) NSFont *font; // default is nil (system font 17 plain) @property(nonatomic, strong) NSColor *textColor; // default is labelColor @property(nonatomic, assign) NSTextAlignment textAlignment; NSTextAlignmentLeft @property(nonatomic, assign) NSContentVerticalAlignment contentVerticalAlignment; // default is NSContentVerticalAlignmentTop @property(nonatomic, assign) NSLineBreakMode lineBreakMode; // default is NSLineBreakByTruncatingTail. used for single and multiple lines of text // the underlying attributed string drawn by the label, if set, the label ignores the properties above. @property(nullable, nonatomic,copy) NSAttributedString *attributedText; // default is nil // the 'highlight' property is used by subclasses for such things as pressed states. it's useful to make it part of the base class as a user property @property(nullable, nonatomic,strong) NSColor *highlightedTextColor; // default is nil @property(nonatomic,getter=isHighlighted) BOOL highlighted; // default is NO @property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled; // default is NO @property(nonatomic,getter=isEnabled) BOOL enabled; // default is YES. changes how the label is drawn @property(nonatomic, copy) void(^mouseDownBlock)(NNLabel *sender); ActionBlock :(void(^)(NNLabel *sender))block;Copy the code

Example

lazy var labelOne: NNLabel = { let view = NNLabel(frame: .zero) // view.contentVerticalAlignment = .top // view.textAlignment = .left view.highlightedTextColor = NSColor.red // IsHighlighted = true view.toolTip = "SOHO China (Hk) co., LTD. ; // view.text = "March 25, 2019, SOHO China Co., LTD released the 2019 annual results announcement." View.text = """ oN March 25, SOHO China Limited released the 2019 annual results announcement. This may be SOHO China's last annual report. On March 10, the share price jumped 37 percent to HK $4.10 on market news that Blackstone was offering to take SOHO Private at a premium of HK $6 per share. The company later confirmed that a deal was in the works. "Middle of the road" is probably the best word for this annual report, with rumours of asset sales in 2019 often resulting in no big asset sales and only minor changes to core financial figures. The chairman of the company, Pan Shiyi, did not seem to pay attention to the annual report. The 2018 chairman's report was four pages long, and Pan shared with the shareholders the real estate situation in China, the development philosophy and goals of SOHO China. However, in the 2019 annual report, the chairman's report is only two pages long, giving a brief account of the overall market situation and the project situation. It does not mention privatization, which is the biggest concern of shareholders, or even the entire annual report. """ // view.isUserInteractionEnabled = true // view.isEnabled = false view.actionBlock { (sender) in DDLog(sender) } // view.textColor = NSColor.lightBlue // view.font = NSFont.systemFont(ofSize: 17) return view; } ()Copy the code

Github