Reference: Using auto-layout to calculate table cell height
In ‘Using auto-layout to calculate table cell height’, it’s introduced how to use auto-layout to update table view’s (UITableView) cell height with Objective-C language. However there is different at NSTableView.
Here I will introduce to do similar thing at NSTableView with Swift language. Remember one thing post ‘Using auto-layout to calculate table cell height’ has warned that this method is not that efficient, figure out the way make it more efficient yourself.
To make a iMessage-like chat table view, there is several steps to follow:
Text field should be able to adjust its size automatically. Image view of bubble should adjust automatically relative to text field. Table view’s row should be fitted into the row cell’s subview, which include text field and image view. Let scroller auto scroll to bottum. Here I use View-based NSTableView to make these:
Table view settings There is some import constraints to make the three components, NSImageView, NSTextField, NSTableViewCell, keep corresponded size, which is showed below:
Dynamic library (with .dylib suffix at UNIX-like OS) is a kind of library discriminated from static library (with .a suffix). Static library will be linked at linking stage instantly after codes are compiled, before binary product output. And instead library is loaded at runtime, I mean load but not link. Load means the executable file will search for binary library when they need it. That’s why some app will announce you that it lack a lib when you double click them for running happily.