• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Problem adding a background NSImageView in a Cocoa View
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem adding a background NSImageView in a Cocoa View


  • Subject: Re: Problem adding a background NSImageView in a Cocoa View
  • From: Jorge Castellanos <email@hidden>
  • Date: Thu, 29 Nov 2007 18:39:13 -0500


It appears that it has a WaveformViewDemoView as its main view, and everything else is a
subview of this.


Yes, you could do thatt without writing custom code. In other words, just set an NSImage view to cover all the background and then add all other controls as subviews. The problem with this solution is that managing and maintaining controls in IB becomes a bit tricky.


(2) you can still set a backdrop image if you override drawRect in your topmost Cocoa view that contains all the sub views (in my example this is drawRect in WaveformViewDemoView). I guess this is what Jorge was getting at. I am using the following code (which isn't clean because in a real app you wouldn't load the image everytime you need to redraw but you get the idea):

Two comments:

a) An easier way of doing it is getting rid of the background custom view in IB, and just set the "CustomView" of your window to be of the class of your view that draws custom code. You can do this from IB. Just select the window, switch to "outline view" and set the class of the custom view to be of type "myBackgroundDrawerView".
This way is transparent and simple.


b) The code you wrote below works, but there is an easier and shorter way to do it using Cocoa. In drawRect stick the following code:

		// Load the image.
	NSImage *anImage = [NSImage imageNamed:@"imageName"];

// Find the point at which to draw it.
NSPoint backgroundCenter;
backgroundCenter.x = [self bounds].size.width * 0.5;
backgroundCenter.y = [self bounds].size.height * 0.5;

NSPoint drawPoint = backgroundCenter;
drawPoint.x -= [anImage size].width * 0.5;
drawPoint.y -= [anImage size].height * 0.5;

// Draw it.
[anImage drawAtPoint:drawPoint fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];



Hope this helps!

jorge castellanos



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Problem adding a background NSImageView in a Cocoa View
      • From: "tahome izwah" <email@hidden>
    • Re: Problem adding a background NSImageView in a Cocoa View
      • From: "tahome izwah" <email@hidden>
  • Prev by Date: Re: AAC recording issues
  • Next by Date: Re: Problem adding a background NSImageView in a Cocoa View
  • Previous by thread: Re: Core Audio and Soundfonts
  • Next by thread: Re: Problem adding a background NSImageView in a Cocoa View
  • Index(es):
    • Date
    • Thread