自定义NSTextFieldCell以不同方式绘制文本

时间:2017-01-22 16:42:05

标签: cocoa nstableview nstextfieldcell

我有基于视图的NSTableView,有2个文本列。

第一列使用自定义NSTextFieldCell。第二列使用默认单元格。

这是自定义单元格代码:

 db.collection('shifts').aggregate([
    {
        "$match": {
            "jobId": ObjectId(job._id),
            "from": { "$gte": new Date() }
        }
    },
    {
        "$project": {
            "hourlyRate": {
                "$cond": [
                    {
                        "$not": { 
                            "$setIsSubset": [
                                [{ "$dayOfWeek": "$from" }], 
                                [1, 7] 
                            ] 
                        } 
                    }, 20,                                
                    { 
                        "$cond": [
                            { "$eq": [
                                { "$dayOfWeek": "$from" }, 
                                7
                            ] },
                            25,
                            { 
                                "$cond": [ 
                                    { "$eq": [
                                        { "$dayOfWeek": "$from" }, 
                                        1 
                                    ] },
                                    30,
                                    "$hourlyRate"
                                ]
                            }
                        ]
                    }                   
                ]                   
            }               
        }
    }
], function(err, docs) {
    var ops = [],
        counter = 0;

    docs.forEach(function(doc) {
        ops.push({
            "updateOne": {
                "filter": { "_id": doc._id },
                "update": { "$set": { "hourlyRate": doc.hourlyRate } }
            }
        });
        counter++;

        if (counter % 500 === 0) {
            db.collection('shifts').bulkWrite(ops, function(err, r) {
                // do something with result
            });
            ops = [];
        }
    })

    if (counter % 500 !== 0) {
        db.collection('shifts').bulkWrite(ops, function(err, r) {
            // do something with result
        }
    }       
})

自定义(第一)列中的文本字段看起来有所不同(更薄?)。 这是screenshot(Sierra)。

不确定发生了什么,可能是自定义实现使用不同的抗锯齿设置。

我在那里错过了什么?提前谢谢。

编辑:提到基于视图的NSTableView

1 个答案:

答案 0 :(得分:1)

看起来该错误今天仍然存在。覆盖pd.read_csv()NSTextField.draw(_ dirtyRect: NSRect)并仅调用NSTextFieldCell.draw(withFrame cellFrame: NSRect, in controlView: NSView)就足以重现此行为。

作为一种解决方法,设置super,将文本字段放入textField.drawsBackground = false或自定义NSBox中,并在那里处理图形。

相关问题