The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > Community > Omni Lounge
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
NSTableView Cell background image weird problem Thread Tools Search this Thread Display Modes
I am trying to display Transparent image for Normal cell and the Opaque color, Green for the Selected cell.

I could manage to do this way. Normal case happens well and once selected Green colored image is shown. But once I select other one then the Green color image in the previous cell remains same. How can I resolve this.

I can't upload images thats why I am giving the details like this


Normal Normal Normal
Normal -> Select 2 -> Highlight -> Select 3 -> Highlight
Normal Normal Highlight

This is with only the problem for Transparent image. If it is opaque then no issue.

Here is my sample code
Code:
@implementation CustomTableView

- (void)awakeFromNib
{
	NSLog(@"CustomTableView awakeFromNib");
	[[self enclosingScrollView] setDrawsBackground:NO];
}

- (void)drawBackgroundInClipRect:(NSRect)clipRect
{
	NSLog(@"CustomTableView drawBackgroundInClipRect");
}

#pragma mark -
#pragma mark Selection Highlighting

- (id)_highlightColorForCell:(NSCell *)cell
{
	// we need to override this to return nil
	// or we'll see the default selection rectangle when the app is running 
	// in any OS before leopard
	
	// you can also return a color if you simply want to change the table's default selection color
    return nil;
}

@end

@implementation CustomTableCell
- (void)drawInteriorWithFrame:(NSRect)theCellFrame inView:(NSView *)theControlView
{
	NSLog(@"CustomTableCell drawInteriorWithFrame");
	NSImage *bgImage = [NSImage imageNamed:@"DefaultCell"];
	
	// Make attributes for our strings
	NSMutableParagraphStyle * aParagraphStyle = [[[NSMutableParagraphStyle alloc] init] autorelease];
	[aParagraphStyle setLineBreakMode:NSLineBreakByTruncatingTail];
	[aParagraphStyle setAlignment:NSCenterTextAlignment];
	
	
	
	// Title attributes: system font, 14pt, black, truncate tail
	NSMutableDictionary * aTitleAttributes = [[[NSMutableDictionary alloc] initWithObjectsAndKeys:
											   [NSColor blackColor],NSForegroundColorAttributeName,
											   [NSFont systemFontOfSize:21.0],NSFontAttributeName,
											   aParagraphStyle, NSParagraphStyleAttributeName,
											   nil] autorelease];
	
	// Make a Title string
	NSString *	aTitle = [self stringValue];//[NSString stringWithString:@"Title"];
	// get the size of the string for layout
	//NSSize		aTitleSize = [aTitle sizeWithAttributes:aTitleAttributes];

	// Icon box: center the icon vertically inside of the inset rect
	/*
	NSRect		anIconBox = NSMakeRect(anInsetRect.origin.x,
									   anInsetRect.origin.y + anInsetRect.size.height*.5 - anIconSize.height*.5,
									   anIconSize.width,
									   anIconSize.height);*/
	NSLog(@"CellFrame:[%f %f] [%f %f]", theCellFrame.origin.x, theCellFrame.origin.y, theCellFrame.size.width, theCellFrame.size.height);
	NSRect anIconBox = theCellFrame;
	NSRect aTitleBox = NSMakeRect(theCellFrame.origin.x, 
								  theCellFrame.origin.y + theCellFrame.size.height/2-10,
								  theCellFrame.size.width,
								  theCellFrame.size.height);
	

	if(	[self isHighlighted])
	{
		// if the cell is highlighted, draw the text white
		[aTitleAttributes setValue:[NSColor whiteColor] forKey:NSForegroundColorAttributeName];
		bgImage = [NSImage imageNamed:@"FocusedCell"];
	}
	else
	{
		// if the cell is not highlighted, draw the title black and the subtile gray
		[aTitleAttributes setValue:[NSColor orangeColor] forKey:NSForegroundColorAttributeName];
	}
	
	// Draw the icon
	[bgImage drawInRect:anIconBox fromRect:NSZeroRect operation:NSCompositePlusLighter fraction:1.0];
	
	// Draw the text
	[aTitle drawInRect:aTitleBox withAttributes:aTitleAttributes];
	
	
	
	
	
}
@end

@implementation TableViewController

- (id)init
{
	NSLog(@"TableViewController init");
	self = [super init];
	if(self) {
		mItems = [[NSArray arrayWithObjects:@"Value1", @"Value2", nil] retain];
	}
	return self;
}

- (void)awakeFromNib
{
	NSLog(@"TableViewController awakeFromNib");
	// set the custom cell as the table view's cell class
	CustomTableCell * aCustomCell = [[[CustomTableCell alloc] init] autorelease];
	[[mTableView tableColumnWithIdentifier:@"theTableColumn"] setDataCell:aCustomCell];
	[mTableView setRowHeight:50.0f];
}

#pragma mark -
#pragma mark NSTableView Data Source Methods
- (int)numberOfRowsInTableView:(NSTableView *)theTableView
{
	NSLog(@"Tableviewcontroller numberOfRowsInTableView");
	return [mItems count];
}


- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
	NSLog(@"Tableviewcontroller objectValueForTableColumn");
	return [mItems objectAtIndex:row];
}

@end
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Weird style problem, transparent background JulienM OmniFocus 1 for Mac 1 2013-03-03 05:39 AM
Background Image - How to stop tiling? mockman OmniOutliner 3 for Mac 0 2012-06-11 08:17 PM
How can I set Transparancy on background for a PNG image export? Eumenides OmniGraffle General 2 2011-09-16 07:16 AM
Background image for ipad version Hughjc OmniGraffle for iPad 2 2010-08-03 09:15 AM
Full image background for canvases hardcoreUFO OmniGraffle General 0 2007-09-11 11:41 AM


All times are GMT -8. The time now is 11:53 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.