【问题标题】:How to not truncate text in NSCellTextView Swift 5如何在 NSCellTextView Swift 5 中不截断文本
【发布时间】:2019-07-04 22:20:36
【问题描述】:

我用一些数据填充了一个 NSTableView,其中一个单元格截断了文本。

我已经搜索了如何不截断此字符串,但我只找到了指示如何自愿截断文本的资源。

我这样填写文本:

extension MessagesViewController: NSTableViewDelegate {
    func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {

...
...
...

    /* Set the information in a cell and return it. */
    if let lCell: NSTableCellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: lCellIdentifier), owner: nil) as? NSTableCellView {
        lCell.textField?.stringValue = lText
        lCell.imageView?.image = lImage ?? nil
        lCell.textField?.toolTip = lText
        lCell.textField?.autoresizesSubviews = true
        //lCell.textField?.
        return lCell
    }

我得到的结果如下:

我希望“数据”字段显示字符串的全部内容。我调整了列的长度以使其适合。

任何帮助将不胜感激, 谢谢, 丁香

【问题讨论】:

  • 您是否调整了文本字段的大小?
  • 我找到了如何做到这一点,我很惊讶地发现在我的情况下默认情况下约束没有设置为填充单元格。

标签: swift macos interface-builder nstableview nscell


【解决方案1】:

因此,似乎当您拥有NSTableCellView 时,您必须手动调整内部的 NSTextField 的大小并设置约束。此框的默认值似乎已将其设置为不适合单元格。

注意默认值!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-14
    • 2016-07-17
    相关资源
    最近更新 更多