Tuesday, April 25, 2017

#1 2017-04-21 03:05:28 am

jaspersiegers
Member
From: The Netherlands
Registered: 2006-08-30
Posts: 38

Change Text Color in Table upon selecting

Hi,

So I have a view based Table View with some Text Fields. The text fields have a different color: one is black, one is gray.
When you select this view the black text field will turn to white but the gray one stays gray and becomes almost unreadable. Most Mac OS applications will make all the text fields white and that is what I'm trying to do.

I've found the NSBackgroundStyleDark method but I am clueless how to implement this.
Has anyone had any luck with this in AppleScriptObjC? And if so how would one do this?

Thanks in advance.

Jasper

Offline

 

#2 2017-04-21 08:44:37 pm

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 4996

Re: Change Text Color in Table upon selecting

Sadly, I suspect the best answer is to pick another color. I've dealt with something similar by changing the way table rows appear when selected, so they just have an outline, but I suspect the code would be far too slow in ASObjC.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#3 2017-04-22 01:09:02 am

jaspersiegers
Member
From: The Netherlands
Registered: 2006-08-30
Posts: 38

Re: Change Text Color in Table upon selecting

Hmm that's to bad.

I came across this objective-C code though. It's a delegate of the ItemCellView.
Could this be done in ASOC?

Applescript:


- (void)setBackgroundStyle:(NSBackgroundStyle)backgroundStyle {
   NSColor *textColor = (backgroundStyle == NSBackgroundStyleDark) ? [NSColor windowBackgroundColor] : [NSColor controlShadowColor];
   self.detailTextField.textColor = textColor;
   [super setBackgroundStyle:backgroundStyle];
}

Offline

 

#4 2017-04-22 01:41:44 am

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11437
Website

Re: Change Text Color in Table upon selecting

Basically it's possible if the model of the table view is a custom class.

• Create a property textColor with the default (NS)Color in the custom class
• Bind that property to the Text Color properties of the text fields in Interface Builder (Table Cell View > objectValue.textColor).
• Implement the delegate methods tableView:selectionDidChange and tableView:objectValueForColumn:row in controller class.
• When the delegate method is called enumerate selectedRowIndexes and set textColor of the model accordingly.

Last edited by StefanK (2017-04-22 03:39:57 am)


regards

Stefan

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.039 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)