I want to use a taller (27pt) view as the divider for a NSSplitView which is vertically-stacked (splitView.isVertical = false). Is there an intended way to do this? If not, is there a common hack?
I was thinking of using a thin divider and listening for mouse drags in the custom view, and using those to programmatically change the divider's location. Is this a valid approach?
An approach that doesn't require listening to mouse drags or any active updating of the view is to use auto layout:
1. Override dividerThickness to return your ideal thickness.
2. Override dividerColor to return clear if your custom view is not opaque and if you don't want the default grey showing through.
If you have a minimum deployment target of 10.11 or later:
3a. Set arrangesAllSubviews to NO on the split view and then add the custom divider view as a subview of the split view. (without setting arrangesAllSubviews to NO, adding the custom divider view would add it as a split pane)
Otherwise, if your minimum deployment target is < 10.11 (or you otherwise cannot set arrangesAllSubviews to NO):
3b. Add a your custom divider as a subview of the container of the split view, but making sure it's higher in subview/z-order
4. Add constraints to position that view where the divider would be, e.g.:
let constraints = [dividerView.topAnchor.constraint(equalTo: topPane.bottomAnchor),
dividerView.bottomAnchor.constraint(equalTo: topPane.bottomAnchor),
dividerView.leadingAnchor.constraint(equalTo: splitView.leadingAnchor),
dividerView.trailingAnchor.constraint(equalTo: splitView.trailingAnchor)]
NSLayoutConstraint.activate(constraints)
Auto layout will take care of updating the position of the divider view when the user drags.
Related
How to design the following layout with StackView
I know that it can be easily created without using stackview but is it possible using stackview because i have lots of ui which already designed using stackview how can i add divider between views like above image
For that i set the following constraints
**But run time it shows like **
You can use some simple Autolayout constraints to get this kind of interface with a UIStackView.
The below image describe the hierarchy and constraints that you can apply:
Also the Accept and Reject buttons have Equal Width constraint.
Output screenshot:
You can do that using UIStackViews, here is how:
First, create a subclass of UIView to use as the class of the UIView in between the 2 buttons.
class CustomWidthView: UIView {
override var intrinsicContentSize: CGSize {
return CGSize(width: 1, height: self.frame.height)
}
}
You only need to override intrinsicContentSize.
Now, add your 2 buttons and an empty UIView between them, and set the class of the UIView to be CustomWidthView. Embed your 2 buttons and the view between them in a stack view, and set the position of the stack view properly using the appropriate constraints.
Select the stack view and from Attributes inspector, find the property named Distribution and from the drop down menu next to it, select Fill Proportionally.
To reflect your changes in the UI Builder, select the custom width view and go to Size inspector, go down to the bottom of the list and you'll find a property called Intrinsic Size, change its value to be Placeholder, and from the width drop down menu, select 1.
There may be a better way to achieve this, but this is the one I found for now and I'd like to find a better one.
Since UIStackView uses auto layout to arrange its subviews, you can modify its behavior by creating constraints.
I assume you have three views in the stack: the accept button, the divider, and the cancel button.
Create two constraints:
An equal-width constraint between the accept button and the cancel button.
A fixed-width constraint on the divider (presumably setting its width to 1).
See also this Q&A.
I create UIToolbar with interface builder and want to add two custom right buttons, but without a space between them. I don't want solution to reset a margin from the right edge, because I found it here but want only reset margin between buttons.
How should I do this?
Thanks.
Instead of a button, use an UISegmentedControl and set its momentary property to yes.
Add one segment for each button you want (in this case two segments)
Then add an IBAction and use a switch to know what index has been selected.
Index 0 first button, index 1 second button.
Create a bar button item with a custom view where that custom view has 2 UIButtons as subviews. In this way you can exactly size and position the buttons as you require.
To adjust space between UIBarButtonItem's you can use a UIBarButtonItem with style UIBarButtonSystemItemFixedSpace and setting its width property.
You can move items closer to eachother than the default spacing by setting the width of the spacer item to be a negative value.
One thing to consider is future-proofing whichever solution you choose. Buttons in iOS6 have nice borders and shading. They may not in the near future...
For a simple example lets say I have a UITextView with a Button underneath it. These two controls are siblings both embedded in a parent UIView.
I now change the text within the UITextView and resize it accordingly. Is there a way to make the button automatically move to have the same relative distance to the bottom of the UITextView? This may seem trivial for this case, but I will have a longer hierarchy with multiple UITextViews that change and it would be nice not to have to calculate the height of every object manually.
One way to approach this would be with a table view: if you place each of your text views within its own table view cell, the table view will automatically calculate its total height from individual calls to its delegate’s -tableView:heightForRowAtIndexPath: method and lay itself out accordingly. Whenever the height of one of your text views needs to change, you can call -reloadData on the table view to make it lay itself out again. A disadvantage of this approach is that it’s really difficult to animate the height changes; if that’s essential to the effect you’re going for, I’m afraid you’re stuck with doing the entire layout manually.
Try the autoresizingMask property of UIView.
This seems to me as though it would be a common problem, but I can't seem to find the answer anywhere. This question seems to address the issue, but I can't seem to get the solution to work and I'm not sure it's referring to Xcode 4.
When using Interface Builder in Xcode 4 and working with a UIScrollView, is there a way to scroll the view down in Interface Builder itself to view/add/edit controls that are out of the viewable section of the screen? I've managed to push a couple controls down using the arrow keys, but now I can't see them and therefore can't manipulate them in Interface Builder. Scrolling the view in IB would be first prize, but if there's a way to even select the controls using a drop-down menu or whatever so I can push them back up with the arrow keys, that would at least be something. Thanks.
Set the ViewController's Simulated Size to Freeform and set a very large height. E.g: 1000 and voilà! You can now scroll to see all the stuff and add even more! :)
P.S: Remember to set set Fixed when you are finish to avoid problems!
Just a workaround which helps in Xcode4:
Expand the Objects Panel which resides on the left of the Interface Builder view (there is the tiny arrow at the bottom of the panel).
Drag your UIScrollView from the view hierachy and place it on the top level.
Now you can resize it to access more content (scrolling to that content did not work for me).
When you are done adding child views to the scrollview, you need to resize it back to be smaller or the same size as the parent view.
After your changes you would need to put back the scroll view where it belongs in your hierachy
I typically do the following when I want to (have to) build a long scrolling screen:
Set the size of the View Controller to Freeform
Set the height of the top level View to something very large
Arrange all the controls that I want on the View
Select all the controls
Select Editor->Embed In->Scroll View
Set the size of the View Controller back to normal (typically Inferred)
Well, there are a few different things you can do. There is a list of items in your view you can open on the left of the workspace by clicking the button that looks like a little play button on the toolbar. Double clicking any item selects it so you can use the arrow keys.
The best option is to use the layout panel (typically on the right) and enter position values manualy. Sometimes I will use this to move my scrollview up to where I can see where I'm working then move it back.
I found a solution although you have to use a Table view controller. If you define the table as static, the scroll works in interface builder when the table is bigger than the windows size. Moreover, a standard view can be added to the top and bottom of the table, these views are scrollable as well. The scroll is made once the controller is selected. I hope you find this trick useful.
I know this isn't exactly what you were looking for, but I always just drag the scroll view out of the view controller onto the "pasteboard" where you can resize it at will and see the whole thing.
Once I make my edits I simply resize it to fit it's allotted space in my view and place it back in the view controller.
set the root view to freeform and ~1000 pt height, go through the child views and set them to this height as well(including scroll view), in the viewdidload method set the height to the appropriate size.
How can I implement tweetie like swipe menu?
I'm done with developing a tableviewcontroller with a customcell. The customcell implements touchesbegan and touchesMoved. It also reports swipe gestures via a selector to the parent tableviewcontroller.
Now how should I go about hiding the "Swiped" cell and replacing it with a "swipe menu view" and how should I get the actions from the buttons present on the swipeview?
Each table view cell has a contentView that encompasses the whole area of the cell. Add your swipe-menu view as a single container view with an opaque background to the contentview so it's on top of everything else. Position it so it's flush left (x=0), set the width to 0, and set it as hidden. That single container can include any other subview (buttons, etc) and you can set the cell view itself as the target of the button events (then bubble it up to the parent table view along with cell index information).
When time comes to show it, set it to not hidden then use UIView animation to make the container width go from 0 to full table width. Set the duration pretty low (i.e. 0.2 seconds) so it's zippy. When you run the animation, the swipe-menu shows up over everything else in the cell content view. To make it disappear just reverse it (set the width to 0 in a UIView BeginAnimation block). You may also want to set an animation completion handler at the end and do some housekeeping there (set the container view to hidden, release memory, etc).
I've done a tweetie like menu, there's no full code but i blogged about it. Hope it helps!
http://petersteinberger.com/2010/01/tweetie-like-swipe-menu-for-iphone-apps/