0

My Cocoa app has a view-based table view.

The table displays a week of the calendar, where each column is a day from (say) Sunday to Saturday.

I would like to highlight the column that corresponds to "Today" in some way; ideally, give a colored background to the textfield, with rounded corners; something like this:

enter image description here

(this is trivial to achieve in iOS. On macOS, with cells etc. instead of views and layers, everything seems so much more complicated...)

However, I am not even able to change the header cell's text or background color. The code below (Swift 3) is executed, however all column headers is displayed with the default colors :

let columns = tableView.tableColumns

// (currentWeek is an array of NSDate)
for (index, day) in currentWeek.enumerated() {        

    let column = columns[sundayIndex + index]

    if Shared.calendar.isDateInToday(day) {
        // THESE TWO LINES ARE EXECUTED, BUT...

        column.headerCell.textColor = NSColor.red 
        // ...NO EFFECT

        column.headerCell.backgroundColor = NSColor.black 
        // ...NO EFFECT
    }

    // THIS WORKS FOR EVERY ROW:
    column.headerCell.stringValue = formatter.string(from: day)  
}
Nicolas Miari
  • 16,006
  • 8
  • 81
  • 189
  • It's limited but you can use `attributedStringValue` and `NSAttributedString`. Or, if you only want the titles, create your own header. – Willeke Aug 29 '16 at 11:14
  • I would, but it seems harder than it looks... will look into that though. – Nicolas Miari Aug 29 '16 at 12:12
  • Similar questions: [Modifying Table Headers on Mac](http://stackoverflow.com/questions/4753282/modifying-table-headers-on-mac) and [How do I override layout of NSTableHeaderView?](http://stackoverflow.com/questions/32666795/how-do-i-override-layout-of-nstableheaderview) – Willeke Aug 29 '16 at 16:51

0 Answers0