how to place some label on some window? - objective-c

I need to mark some opened window from my application. I can get the windows list, their system id, name, owner... Can I draw some NSImage only on choosen window?

If you have a window, as you say you do, you could add a NSImageView as a subview of that window. This NSImageView should be set to have a frame the same size as the window in question so it fills the window.
If you need to do custom drawing you could subclass the NSImageView and override its drawRect: method or you could just set its image property to an image that you have already created and added to the apps bundle.
Hope this is what you mean.

Related

Strange UIImageView issue

I added a UIImageView to my View Controller's main view using interface builder.
Then I just set the image of the UIImageView in the properties.
When I run the app I can't see the image. What can be wrong? Thanks
PS. On the XIB file, if I select the image, I can see it - once I remove focus
from it, it seems like it went to the "back" of the main view (because it is still there, I can see it in the "Objects" window of the XIB file).
pps. It works if I use a different image. Could it be that it was because previous image was with transparent background? (although it still had some icon).

Setting subview's width equal to window width on launch

I'm struggling getting a subview (which is acting as a custom toolbar [I need a NSView rather than an NSToolbar]) centred within an INAppStoreWindow..
The subview is being added correctly, and stretches correctly only if the window is exactly the same width as the custom view that I've created in IB.
If the window opens wider than the custom view, it does not stretch properly. The window seems to open in exactly the same state as I left it (in Lion), which therefore means I have to set the width of the custom view to the restored window width on launch.
It's also important that the buttons etc I have placed in the centre of the view in the nib remain centred...
How do I do this?
Edit: to make this clear, how do I get a restored window's width? I have set it to 480 in the nib file but if I resize the window, quit then restart the app, window.frame.size.width still returns 480, not the width I quit with..
Many thanks
I take it you are not creating the NSWindow in interface builder, you can override -[NSView viewDidMoveToWindow] or -[NSView viewWillMoveToWindow] to set the width, there are also viewDidMoveToView equivalents which may make more sense since you view gets added to the NSWindows contentView, there is also awakeFRomNib which you can override which may b he better choice if you only have to worry about the issue once when you vie loads from the Nib file.

How to keep NSPanel within NSScreen visibleframe always

I have one floating NSPanel in my app, which user can move using mouse. I want my NSPanel to always visible within main screen. I want code to reposition my NSPanel with its original width and height within screen border in all the sides.
Thanks,
Subclass NSPanel and override the frame-relative methods. setFrameOrigin:, setFrame:display: and maybe others (see the documentation to find out all the methods). There is also promising - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen method.

How to resize view in XIB?

I'm trying to follow these instructions with Xcode 4, but am unable to resize the xib. Does anyone know how? ( The width and height cannot be clicked upon ) Also there is no UITableViewController so I just used UIViewController.
EDIT - My goal is actually not to use the popover controller, I simply want to create a modal login dialog following the example here: How to resize a UIModalPresentationFormSheet? and am trying to make the view controller 300x400
A popover controller has to have a
view controller inside of it. So we
need to create a new view controller.
Go to File > New File > Cocoa Touch
Classes > UIViewController >
UITableViewController subclass >> With
XIB for UI >> Targeted for iPad. Name
it OptionsViewController. Drag your
viewcontroller.h and viewcontroller.m
files into the classes group and the
new XIB into the resources group.
Open the XIB and go to the Size
inspector. Change the width and height
properties to 250 and 300. Save your
file and close interface builder.
It appears that in Xcode 4.5+, just to be annoying: Apple changed this again.
Instead, you now have to:
select the viewcontroler
select the "size" dropdown
set it to "Freeform"
...which removes their "block" on editing the size fields.
(this is pretty close to how I expected it to work in the first place, but I have to say it's not easy to find - you have to edit a different value on a different screen (with no help from Apple), in order to un-break the edit field on the correct screen. Not good design!)
Interface Builder (and the IB equivalent in Xcode 4) won't let you change the size (or autosizing attributes) of a top-level view when any Simulated User Interface Elements are enabled.
Select your view, and in the View Attributes inspector set Status Bar, Top Bar, and Bottom Bar to Unspecified. You should then be able to change the size.
In swift 4.2 interface builder won't let you change the size
click on the view and open the attribute inspector and change top, bottom bar to none and size to freeform. Now you are good to go for the change in size.

How can I make an undecorated window in Cocoa?

I like to create a Cocoa window without any chrome whatsoever. The only thing the user should see is what I draw.
I've discovered I can create a custom NSView but does this have to be in an NSWindow to display? If not, how can I display it without putting it in an NSWindow? If it does have to be in an NSWindow, how do I stop the window from drawing a title bar and other chrome?
Check out the sample:
http://developer.apple.com/samplecode/RoundTransparentWindow/index.html
I've discovered I can create a custom NSView but does this have to be in an NSWindow to display?
Yes.
If it does have to be in an NSWindow, how do I stop the window from drawing a title bar and other chrome?
Use NSBorderlessWindowMask when you create your window. (Assuming you aren't using a custom subclass of NSWindow, this means not creating the window instance in a nib. If you want to lay out your view hierarchy in a nib, do that in a top-level custom view, then load the nib and set that view as the window's content view.)