Get layout frame of NSView (i.e. ibLayoutInset) - objective-c

I'm working on an Interface Builder-type app for interface design. I would like to be able to align NSView's along their layout frames. Is there a way to access the ibLayoutInset property from my code?

Check out the Interface Builder Kit's NSView additions. Is that what you're looking for?

Related

Moving a button in a ViewController from a NSObject class (adjusting to 4" screen)

I am working on adjusting all my iPhone screens to the new iPhone 5 4" screen. To make the code easier to manage i would like to use an NSObject class to do this that calls on a ViewController to move a button or whatever needs to be moved.
Would someone please give me some hints how to accomplish this or if there is a better way of doing this.
I recommend you look into using Auto Layout. It will do everything you need.
If you are talking about autoresizing then i am sure the shared link will work
Autoresizing masks programmatically vs Interface Builder / xib / nib
you can resize your button and view programmatically as well as using interface builder.

Create custom buttons for Interface Builder

Does anyone know how to create custom buttons for Interface Builder? Like instead of have just a regular Round Rect Button, I want to have like a custom 3D button and some random image background for that button. How to do this?
You will either need to find a third-party class (ideally with an Interface Builder plug-in so you can see it live in the IB file) or subclass UIButton or NSButton/NSButtonCell for Mac and provide your own 3D rainbow unicorn drawing behavior. :-)
Interface Builder can only show you classes it knows about - you can't add behavior / modify existing drawing behavior there because that's the wrong tool for the job. You'll need to find someone else's or subclass your own in code then let IB know about it.
Update based on OP's comment
You can use -setImage:forState: to supply your custom image for the given states.
To do it in Interface Builder is prohibitively complicated (writing an Interface Builder plugin is a non-trivial task). However, you can subclass UIControl (which is just a UIView) and define your custom drawing in the subclass.
Then, in Interface Builder, change the class of the object you've subclassesed to your new class, and everything should work correctly.
Relevant reading:
How to override -drawrect in UIButton subclass?
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIControl_Class/Reference/Reference.html
http://www.cocoabuilder.com/archive/cocoa/284622-how-to-subclass-uibutton.html (If you really need to subclass UIButton instead)
It's probably easiest to use an image as the background for the button. For example you can use this tool to easily generate buttons with gradients, http://itunes.apple.com/us/app/uibutton-builder/id408204223?mt=8
If you want anything more fancy it's probably time to start Photoshop ;-)

NSWindow with custom shadow

I want to draw a custom shadow on an NSWindow-Object.
Is there a way to do this by passing an own NSShadow-Object to NSWindow? Or a (private) method, where I can put my own drawing code?
Thanks,
Don't. You shouldn't alter the look of the window. Changing the look of UI is only allowed for Apple. Normal apps should use the standard one.
That said, there's a way, if you really insist on doing that. You can't just attach an NSShadow, unfortunately. Also, as far as I understand, there's no private method which draw the shadow. That's done by the Window Server, not by the app.
But you can ask the window server not to add the shadow. Have you noticed that in the Interface Builder, there's an option suppressing the shadow of a given window? That corresponds to the property hasShadow of an NSWindow.
After suppressing the shadow, you just need to draw everything by yourself. A nice sample code that does the custom window drawing is available at ADC, so have a look at it.

Subclassing an NSDrawer's contentView to implement a completely custom drawer

I want to implement my own custom drawer completely by subclassing NSView and doing all my view drawing in that. I've created a custom NSView class that does hardly anything apart from implement initWithFrame: and drawRect: which I've got logging the frame/bounds of the NSView (which is reporting correctly). I've also instantiated this view and added it to the NSDrawer object in my application using setContentView: so that it uses my custom NSView.
However, this still draws a default drawer layout attached to the edge of my applications NSWindow. How do I override this default style so that I can draw my own drawer (!) in my custom, subclassed NSView without anything default being drawn by the OS? (So that I can control the design and size of the drawer myself, to basically emulate a tab bar that won't act strictly as a traditional drawer.)
I made a custom drawer by subclassing NSWindow rather than NSDrawer. It was a lot of work. There is a private object, NSThemeFrame, that sits between a NSWindow and its contentView. To avoid using private API, you have to make a transparent window and let its contentView act like a NSThemeFrame. Matt Gallagher shows how: http://cocoawithlove.com/2008/12/drawing-custom-window-on-mac-os-x.html
That frame is being drawn by the drawer's frame view. To do this, you need to use some private methods, and the easiest way is probably to use a custom subclass of NSDrawer. I do not know the specific methods used for drawers, but you can get a header for the class including private methods using class-dump.
Edit: This is what NSDrawer actually does.
NSDrawer is an opaque object that manages other objects. It creates a window using the private NSDrawerWindow class. Setting its content view sets the window's content view. The NSDrawerWindow class uses the private NSDrawerFrame class, which is a subclass of the private NSFrameView class, as its background and displays its content view inside that.
To change the frame, you need a way to change the frame view in the window. The easiest thing to do would be to get a header for NSDrawerWindow and add a category that overrides +frameViewClassForStyleMask: to return the class for your custom view. Your custom view should be a subclass of NSFrameView, which means you also need a header for that class.

IPad: can I deal with landscape, portrait orientations solely in interface builder? (non-programmatically)

Let's say we have a very simple view with just a single button.
I'd like this button to flip when the user rotates his ipad. What's the simplest way to do this? Maybe interface builder has some kind of property I can set? I keep hearing something about autoresizingmask but I can't really find it in interface builder.
Thanks
p.s I understand that for more complex views I might need to create two separate views one for landscape and one for portrait and then swap them programmatically with some kind of event. but I'm wondering if for very simple views we can do something easily with interface builder with no need for any code or additional views?
actually i found a pretty simple tutorial that explains this:
http://www.youtube.com/watch?v=f3yb24f8O1Y
then
http://www.youtube.com/watch?v=7lzbVURh4mM