iPhone SDK, selection Rectangle around a view - iphone

I have a Drawing app of sorts and am looking for some feedback on ways to draw a selection rectangle, and or the resize grips for a selected view.
So I have a custom class that is inherited from UIView, in it it contains a UIImageView, UILabel, and UIButton. I can have several on the screen at one time. I want to tap on one and draw a selection rectangle around it. From there if i drag I want the view and the selection rectangle to move with it. I would like the Selection Rectangle maybe 4px larger than the exiting bounds rect.
So my question is what is the best way to get the Selection Rectangle around the selected UIView object?
Do I offset the object so what when I add in the UIImageView, UILabel, and UIButton that are part of it I have a 4px buffer around the edges?
Do I adjust the View when selected to reposition the subview, increase the bounds and offset the frame?
Do I just create a new UIView that is 4px larger than the selected object and just move it with the selected view?
Do I just create a new UIView that is 4px larger than the selected object and and make the selected view a subview of it?
or? (your Idea Here...)
Thank you for your comments and Suggestions...
Scooter133

Consider setting the borderWidth property on your view's layer. Note that this is drawn within the view's bounds, so it may be more useful as a highlight state than a selection rectangle.

Related

AppKit: How can I remove one pixel inset of NSOutlineView

I'm totally new to AppKit. I'm so confused about managing layout of AppKit views.
I have a view which frame is 450*300
and I added an outline view in the view but it has one pixel inset automatically added.
This makes a one pixel border and it makes me annoying.
I can't fix it at all. There's no options about insets, constraints and resizing frame. What I wanna do is just making outline view's size the same as the super view's size so that there's no tiny border.

set margin to collection view's cell

I'm beginner with collection view,
I need to create cell like this
Can I do it from Storyboard?
I want to add margin of cell = 4 or 5 in the top, bottom, lift and right in iPhones and iPads of all sizes, or I if need to do that programmatically How I can add the contents of the cell like the image above?
There is no "margin" here. There is simply a rectangle with a shadow, and everything else is drawn in front of it. The simplest solution is probably a custom UIView that draws itself as a rectangle with a shadow. Make that the content view's direct subview, and everything else in the cell is a subview of that. The inset of the rectangle-with-shadow within the cell's content view can be determined by autolayout (and the position of all the stuff inside it can be determined by autolayout too).
Thus it was trivial for me to obtain this sort of thing:
And of course you can tweak the border color, the background color, and so forth.

NSView equivalent of UIView Clip Subviews?

Is there a way to disable clipping of subviews of NSView? In UIView there is a “clip subviews checkbox” and the backing clipToBounds property, but I cant find anything similar in Cocoa.
Here is my scenario: I have this grey dot that you can drag on the screen:
When the user drags the dot I want to show up and down arrows that I have in the background. The up arrow is outside the bounds of the NSView holding the dot and arrow.
You could use the [NSView frameForAlignmentRect:] method. It defines the frame which is used for the constraints based layout. The actual frame can be much larger to allow displaying the arrows when the view is moved.
Cocoa is using this feature to compensate for shadows or other parts of views which do not "count" as actual frame of a control.
From the documentation:
The constraint-based layout system uses alignment rectangles to align views, rather than their frame. This allows custom views to be aligned based on the location of their content while still having a frame that encompasses any ornamentation they need to draw around their content, such as shadows or reflections.

Shadow inside UIView

I am working on iPhone application development and have come across shadows of UIView.
I know how to show shadows to a UIView but what I am actually interested in is to drop shadow inside the UIView.
Like when I set shadow properties of a UIView the shadow is dropped behind the view. I want it to come over the view so that the view looks as if it is pressed inside.
Example of such view is UITextField with roundedRect styling.
Thanks,
It depends a lot on the final effect you want to achieve.
The easies way would be a custom image with a prebacked shadow as background. This will give the illusion of a recession in the surface of the view. You can then add subviews to it as usual.
Alternatively, you can override the drawRect: method and draw the view as you like there, "inverted drop shadow" included.

How do you create an animation like the iBooks app's moving bookmark?

When you tap the bookmark, it slides down or up smoothly. As it slides up, it disappears as if behind the view directly above it. I know how to animate changing the frame of a view, but I don't know how to make it disappear like that. (I don't want to resize the UIImage, just slide the UIImageView up and out of sight.)
I figure I need an invisible button to toggle the animation, and an UIImageView to animate. Do I need to change the bounds of the UIImageView, or should I use the frame? I thought I could just change the height from X to 0, but it didn't seem to resize the UIImageView. I had a little luck with settings the bounds with clipping subview's enabled, but I wasn't quite there.
I don't think I understand the relationship between the bounds and the frame.
I ended up adding a parent UIView to contain the UIImageView. It has the dimensions in which I want the UIImageView to be viewable in, and then I just animate the frame so the Y dimension is equal to the negative height and it slides up nicely.
I was on the wrong track with the bounds.