I have a button inside a horizontal stack view and am trying to give it a border using the Runtime Attributes in Xcode. Here is what my storyboard looks like:
When I run my app the text has no padding so the border fits very tight:
Is there any way to make the border of the button fit a bit looser? I can't seem to make the UIButton bigger since it's in a stack view...
you can look at lowering the content hugging priority of the add button as both are UIButtons and have same compression resistance and content hugging priority and stack view algorithm in such cases stretches the leftmost view.
You have to set a width constraint on the button.
Related
On iOS by default if you add the button in SwiftUI its size is equal to the size of the text. Setting the padding to some value expands the size to be bigger than the text by that value.
On watchOS by default the button has the text and background with applied padding. I don't see any way to reduce that padding (to make the button height closer to the height of the text). I have tried with setting padding and frame but it doesn't appear to be helpful - it appears even counter intuitive as increasing the padding reduces the height of the visible button but it keeps the overall size of the button in the layout which still isn't helpful.
Just to note that with storyboards this reduction of height is possible so I would assume that there should be a way in SwiftUI.
Set the button’s buttonStyle(:) to PlainButtonStyle() and you’ll have full control over the padding and frame. The downside is that you no longer get the default button background, so you’ll need to recreate it if you need it.
I would like to have two labels in my tableview.
but the label resize option is disabled.
How to have the two labels horizontally?
Select UIlabel instead of the cell and then you can set Auto resize like follow.
You may need AutoLayout and Custom Tableview Call. Use two different labels, e.g. one for username (left aligned text) and another for garbage text (right aligned text).
Now, set Content Compression Resistance Priority for one of both label, according to your requirement for data visibility when there is long texts in user name.
Look at these snapshots:
Labels with default content compression resistance priority
I changed content compression resistance priority for label blablabla blablabla, from 750 to 749.
Result is:
For more details see Apple document: Setting Content-Hugging and Compression-Resistance Priorities
Drag a horizontal UIStackView from object library and set it's constraints like this inside the cell
//
drag 2 labels inside it and make the distribution .FillEqually
//
Are you sure you have selected Label?
If you know about Layout constraints, it will be easier than this auto resizer.
Label 1==> Set Leading, Top & Bottom constraints to SuperView. Set Trailing constraint to Label2.
Label2==> Set Trailing, Top & Bottom constraints to SuperView. Set Trailing constraint to Label2.
Now, after this, it will show Red error arrow. Now, you have to decide which Lable width is a priority. After deciding, select that Lable and set Horizontal Content Hugging to 251(High) and Comprehensive to 751(High). Also, change lower priority label Content Hugging and Comprehensive to 249 and 749 respectively. Now, Red error arrow will not be shown and in the cell it will show all text in both labels without and cut.
if you want a easy and quick fix for it, implement a stack view inside the tableview cell. You can change the stackview as you want and also you dont have to worry about applying constraints.
I use a NSStackView to dynamically (added by code) display other NSViews, everything works so far, but the sub views are to small.
They try to be as small as possible, regardless the constrains, if i resize the views in IB, they scale correctly
The Header with the hide button does not fill the available space:
I did set the translatesAutoresizingMaskIntoConstraints property to false on the stackview and all subviews
Well, it's hard to know for sure without more information, but the most likely cause is that the horizontal content hugging priority of the labels is higher than the horizontal hugging priority of the stack view. (Note: the former is a general property of all views while the latter is a stack-view-specific property.)
You also need to have constraints between the stack view and its superview to make the stack view stretch the full width. For example, leading and trailing space constraints.
This is quite old, but in modern times I have found that if you set the alignment to width, everything magically works.
stackView.orientation = .vertical
stackView.alignment = .width
stackView.addArrangedSubview(nowFullWidthSubview)
I want to set the content view of a scrollview to whatever the current screen size is, but AutoLayout is doing some funky stuff. This is trivial in code... just create a scrollview with a frame that is the superview's bounds. Then create a content view with the scrollview bounds and populate it and set the alwaysBounces... properties to YES. In interface builder though, this is some kind of sinful thing it seems.
I know Autolayout handles scrollviews totally differently because it wants to infer the content size based on constraints. My approach that failed is setting the scrollview to have 0 distance to its superview (all sides attached). Then, the same with the content view (the single scrollView subview)- attached to all superview edges. Then the precompiler thing complains about not knowing the content size, so I set a width and height constraint at placeholder to be removed at build time. But the result is a (CGRect){0,0,0,0} contentView. The 0 space to trailing edge and bottom of superview are totally ignored.
So how can I make a scrollview with a dynamic content size based on the screen size?
Bonus points if you can explain how you would do the same, but for a content size of 2x screen width.
You can try setting a constraint for the content view's width to equal the scroll view's width (for your bonus question: with a multiplier of 2). Same for height.
Not sure what the point of having a scroll view whose content is always the size of the scroll view is. By definition it wouldn't scroll, right?
I have an NSView as the document of an NSScrollView. I would like to have a few pixels of padding at the top and bottom of the visible part of the view, regardless of where the scroller is positioned (not just at the top and bottom of the document as described here). For an example of an app that does this, look at Terminal.app. Regardless of the background color of the text, the top two visible rows of pixels are always the default background color.
I know I could simply draw everything two pixels lower and draw a rectangle at the top and bottom of the document-visible rect, but that will require changing a lot of complex code that I didn't write. Simpler ideas are welcomed!
The answer to the question you linked is actually a good solution for this problem too. In fact if your view is anything but an NSTextView, I'd say it's easier to implement.
Specifically: make your actual document view a subview of some other view, leaving room around the edges and make that view the scroll view's document view. If your content view (the one you wish to pad) changes sizes, have your "padding view" observe it for frame changes and resize to maintain the padding.
2015 Update
Content inset has been added to NSScrollView as of 10.10, making my older answer obsolete.