Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
How to set text color in a NSPopupButtonCell in an NSTableView
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="tmeehan" data-source="post: 821251" data-attributes="member: 92859"><p>This seems like it should be simple but for some reason I can not get it to work. I've tried a million different things with no success. All I want to do is set the color of the text in a NSPopUpButtonCell. One of my columns in an a subclass of NSTableView contains popup menus. Everything is working great so I move on to the last issue (I hope). I need to be able to set the color of the menu items based on certain criteria. But before I got to that I just tried to change the color from black to anything else. It just doesn't work. Below is the relevant code from my project. I don't usually post this much code but this is killing me and I was hoping someone might be able to spot something I am doing wrong and set me straight. Thanks in advance for any help. Basically, I just have subclasses of NSTableView, NSPopupButtonCell and NSTableColumn. I've stripped out all the junk not relevent to this problem.</p><p></p><p></p><p></p><p>********************* NSTableView Subclass ****************************</p><p></p><p>@interface ListBoxControl : NSTableView {</p><p> MyDataSource *TheDataSource;</p><p> myButtonCellClass *pcell;</p><p>}</p><p>- (void)awakeFromNib;</p><p>-(MyDataSource*) getDataSource;</p><p>-(myNSCell*) getCustomPCell;</p><p></p><p>@end</p><p></p><p></p><p>@implementation ListBoxControl</p><p></p><p>- (void)awakeFromNib;</p><p>{ </p><p> NSAttributedString *redString;</p><p> NSMenu *colorMenu;</p><p> NSMenuItem *theRedItem;</p><p> NSMutableDictionary *red_attrs;</p><p> </p><p> </p><p> TheDataSource = [[MyDataSource alloc] init];</p><p> [TheDataSource retain];</p><p> [TheDataSource initData];</p><p> [TheDataSource setHostView:self];</p><p> [self setDataSource:TheDataSource];</p><p> </p><p> red_attrs = [NSMutableDictionary dictionaryWithCapacity:2];</p><p> [red_attrs setValue<img src="/mac_images/images/smilies/Embarrassed.png" class="smilie" loading="lazy" alt=":[" title="Embarrassed :[" data-shortname=":[" />NSColor redColor] forKey<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite4" alt=":mad:" title="Mad :mad:" loading="lazy" data-shortname=":mad:" />"NSForegroundColorAttributeName"];</p><p> [red_attrs setValue<img src="/mac_images/images/smilies/Embarrassed.png" class="smilie" loading="lazy" alt=":[" title="Embarrassed :[" data-shortname=":[" />NSColor redColor] forKey<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite4" alt=":mad:" title="Mad :mad:" loading="lazy" data-shortname=":mad:" />"NSStrokeColorAttributeName"];</p><p> </p><p> redString = [[[NSAttributedString alloc] initWithString<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite4" alt=":mad:" title="Mad :mad:" loading="lazy" data-shortname=":mad:" />"Red" attributes:red_attrs] retain];</p><p> </p><p> colorMenu = [[NSMenu alloc] initWithTitle<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite4" alt=":mad:" title="Mad :mad:" loading="lazy" data-shortname=":mad:" />"COLORMENU"];</p><p> theRedItem = [[NSMenuItem alloc] initWithTitle<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite4" alt=":mad:" title="Mad :mad:" loading="lazy" data-shortname=":mad:" />"Title1" action:NULL keyEquivalent<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite4" alt=":mad:" title="Mad :mad:" loading="lazy" data-shortname=":mad:" />""];</p><p> [theRedItem setAttributedTitle:redString];</p><p> [colorMenu addItem: theRedItem];</p><p> </p><p> </p><p> pcell = [[[myButtonCellClass alloc] initTextCell<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite4" alt=":mad:" title="Mad :mad:" loading="lazy" data-shortname=":mad:" />"" pullsDown:false] retain];</p><p> [pcell setEditable:NO]; </p><p> [pcell setBordered:NO];</p><p> [pcell setMenu:colorMenu];</p><p> </p><p>}</p><p></p><p></p><p>-(myNSCell*) getCustomPCell</p><p>{</p><p> </p><p> return pcell; </p><p>}</p><p></p><p>-(MyDataSource*) getDataSource</p><p>{</p><p> return TheDataSource; </p><p>}</p><p>@end</p><p></p><p></p><p></p><p>********************* NSPopUpButtonCell Subclass ****************************</p><p></p><p>@interface myButtonCellClass : NSPopUpButtonCell {</p><p></p><p>}</p><p></p><p>@end</p><p></p><p>@implementation myButtonCellClass</p><p></p><p>@end</p><p></p><p></p><p></p><p>********************* NSTableColumn Subclass ****************************</p><p>@interface customColumn : NSTableColumn {</p><p></p><p>}</p><p>- (id)dataCellForRow<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite3" alt=":(" title="Frown :(" loading="lazy" data-shortname=":(" />NSInteger)row;</p><p>@end</p><p></p><p>@implementation customColumn</p><p>- (id)dataCellForRow<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite3" alt=":(" title="Frown :(" loading="lazy" data-shortname=":(" />NSInteger)row</p><p>{</p><p> return [[self tableView] getCustomPCell]; </p><p>}</p><p></p><p>@end</p></blockquote><p></p>
[QUOTE="tmeehan, post: 821251, member: 92859"] This seems like it should be simple but for some reason I can not get it to work. I've tried a million different things with no success. All I want to do is set the color of the text in a NSPopUpButtonCell. One of my columns in an a subclass of NSTableView contains popup menus. Everything is working great so I move on to the last issue (I hope). I need to be able to set the color of the menu items based on certain criteria. But before I got to that I just tried to change the color from black to anything else. It just doesn't work. Below is the relevant code from my project. I don't usually post this much code but this is killing me and I was hoping someone might be able to spot something I am doing wrong and set me straight. Thanks in advance for any help. Basically, I just have subclasses of NSTableView, NSPopupButtonCell and NSTableColumn. I've stripped out all the junk not relevent to this problem. ********************* NSTableView Subclass **************************** @interface ListBoxControl : NSTableView { MyDataSource *TheDataSource; myButtonCellClass *pcell; } - (void)awakeFromNib; -(MyDataSource*) getDataSource; -(myNSCell*) getCustomPCell; @end @implementation ListBoxControl - (void)awakeFromNib; { NSAttributedString *redString; NSMenu *colorMenu; NSMenuItem *theRedItem; NSMutableDictionary *red_attrs; TheDataSource = [[MyDataSource alloc] init]; [TheDataSource retain]; [TheDataSource initData]; [TheDataSource setHostView:self]; [self setDataSource:TheDataSource]; red_attrs = [NSMutableDictionary dictionaryWithCapacity:2]; [red_attrs setValue:[NSColor redColor] forKey:@"NSForegroundColorAttributeName"]; [red_attrs setValue:[NSColor redColor] forKey:@"NSStrokeColorAttributeName"]; redString = [[[NSAttributedString alloc] initWithString:@"Red" attributes:red_attrs] retain]; colorMenu = [[NSMenu alloc] initWithTitle:@"COLORMENU"]; theRedItem = [[NSMenuItem alloc] initWithTitle:@"Title1" action:NULL keyEquivalent:@""]; [theRedItem setAttributedTitle:redString]; [colorMenu addItem: theRedItem]; pcell = [[[myButtonCellClass alloc] initTextCell:@"" pullsDown:false] retain]; [pcell setEditable:NO]; [pcell setBordered:NO]; [pcell setMenu:colorMenu]; } -(myNSCell*) getCustomPCell { return pcell; } -(MyDataSource*) getDataSource { return TheDataSource; } @end ********************* NSPopUpButtonCell Subclass **************************** @interface myButtonCellClass : NSPopUpButtonCell { } @end @implementation myButtonCellClass @end ********************* NSTableColumn Subclass **************************** @interface customColumn : NSTableColumn { } - (id)dataCellForRow:(NSInteger)row; @end @implementation customColumn - (id)dataCellForRow:(NSInteger)row { return [[self tableView] getCustomPCell]; } @end [/QUOTE]
Verification
Name this item 🌈
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
How to set text color in a NSPopupButtonCell in an NSTableView
Top