UIStackView inside a UICollectionViewCell is out of screen - autolayout

I'm trying to use a UIStackView in my cell, but I'm with some problems with the constraints.
When I put the constraints in my stack, the whole content go to outside the view. Note in my screenshots:
this first one is the UIStackView without any constraint. Note, the content has a margin of 5.
now, I've set the constraint in my UIStackView. Note that margin right of content doesn't exists anymore. And now its a negative margin.
Obs: the distribution is fill proportionally
Anyone knows what Im doing wrong?

Everything works just fine. Make sure you have added constraints to all other elements.
Inside UIView with margins:

Related

Angular Material: Textarea with fixed height

I want to have a page which has two main components. On the upper half a textarea on the lower half some input fields. The split should be 50:50. The problem I'm facing:
I cannot tell the textarea to fill the complete height when displayed. I know I can use some cdk..MinRows or ...MaxRows but therefore I need to know the whole height before. Additionally the underline looks also quite strange, e.g.
How to fix it? Does it work with Material or should I use plain HTML textarea? My project

iOS 13 UITableViewCell | Child view gets clipped out

SO I have a UITableView which contains a UITableViewCell and tableView.header is set to a Parallax Header. The UITableViewCell has certain UIViews which are set as negative constraints from Top and are shown perfectly on iOS-12 whereas when observed on iOS-13 the UIViews showing over Parallax Header are clipped. I have tried all possible solutions but unfortunately it still shows the same. My App is opting out of SwiftUI and still running the old code. I have even tried to change the zIndex of the child UIView but still the same. Here are some snapshots and some code:
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
self.PriceView.layer.zPosition = 1
self.PriceView.bringSubviewToFront(self.contentView)
self.PriceView.setNeedsDisplay()
}
This code is functional for iOS-12 but not iOS-13.
UPDATE:
Apple's changelog/documentation for iOS-13 suggests:
The UITableViewCell class’s contentView property is always laid out
edge-to-edge with adjacent accessories, both on the leading and the
trailing side. This streamlines the layout code so developers who want
the correct default offset no longer have to align their content with
the content view border or the layout margin depending on whether
there is an accessory on the trailing side or not. You should now
always lay out their code on the layout margins of the cell’s content
view to get the default system insets. These insets will be adjusted
automatically based on the accessories visible in the cell to match
the system’s default spacing. (48214114)
This is a bit unclear to me and if someone can help me out here.
Here are the snapshots as to how it is showing in iOS-12 which is required and how it is showing in iOS-13 respectively:
And here observe for iOS-13:
Here is also the Constraint Layout of my UITableViewCell's PriceView:
I need both to be consistent on both OSes. THANK YOU SO MUCH FOR THIS HELP!
Wohoo! I finally figured it out. So before as default it was working on iOS-12 but after iOS-13 and UITableViewCell changes as described in the question, it stopped working. Here is what I did:
Firstly, in the Size Inspector, the ContentView of UITableViewCell was set to Safe Area Layout Guide which I turned off and turned on Safe Area Relative Margins, similarly I did the same for the child, as in the PriceView.
Secondly, in the Attributes Inspector, the ContentView's and UITableViewCell's both had their Autoresize Subviews property turned on, I simply turned it off
And voila! It works. Hope anyone who might have these UITableViewCell issues, please note that now its all relative 😉
Actually, what worked for me was unchecking "clip to bounds" from the attribute inspector for the content view

iPhone Autolayout UIText suffocation

I know I can fix this programmatically and I know I could set the text to tighten / scale but I would like to know how to get this text to extend organically to a third line on small screens. How can I accomplish that?
There are a couple of things you need to take care of before your label grows:
Make sure the 'number of lines' field in the attributes inspector is set to zero. Setting it zero allows the label to grow depending upon the content it has.
If the label is in a container view, make sure you haven't specified the height constraint explicitly on the container view. Since the container view should generate its height from its subviews and the subviews will generate their height from the content they have. Its sort of a chain process that goes on if you have a deeper hierarchy.
Make sure there is no sibling view to the container view with an explicit height that might cause your container view to shrink while maintaining its own height. This point may also apply even if your label is not within some container view.
In the image below, the container view(gray one) is bound from three sides allowing it to grow from the bottom.
Below image shows the constraints applied to the content views of the container. The container is driving its height from its content views.
Below I have increased the text of the label from a single line to three lines. At this point the label tries to expand horizontally but since the container view is bind with the super view on both sides the label has only one direction left to increase itself. It increases downwards pushing the textfield and button down and since the button is tied with the bottom of the container view it pulls the container view increasing its height.

How to use size classes in xcode6

Please, is there someone who can help me to understand ho to use Size Classes in Xcode6? I'm designing for the first time a dialer. I set up different constraints, and I have no error message, and in all screens (Iphone3-4-6-6+) I have good aligned keys, but I see keys in the same size in all screen (that's not good for me, because I need they are bigger in Iphone6 and 6+). How can I do to see the right size and the right position of an object, like the key, in this case? I checked the boxes in the right panel "Use size classes" and "use autolayout", and I understood that I have to work in different optional screens that I can select in the bottom of the work area (any-any, compact-any, etc..) but I didn't understand what to do after choising a screen (example compact-any).
Hi as per your question what you need to do when you have Any-Any size class give the constraints which you need to be common for all the views(in your case keys).
e.g. : If you want your view to remain so same height and width you need to set those constraints in Any-Any and in when you change to Custom-Any size class you just need to give constraints related to leading and trailing.
In Any-Any you just need to give widths Equally,aspect ratio and horizontal and vertical spacing between views.
The constraints highlighted in the below image are set in Any-Any Size class.
This constraints are only applied all iphones and iPad in both portrait and landscape mode.
In Compact-Any you just need to set leading,trailing,top and bottom spacing to views from superview or layout margin.
The constraints selected in the below image are set in Custom-Any Size class.
This constraints are only applied to all iphones in portrait and landscape mode and are not applied to iPad.
Result
Here i've not applied bottom constraints to views.
but you can set if you have more controls.
Please refer the answer i've given for multiple controls with auto layout using size class.
https://stackoverflow.com/a/27471120/4101371
You can refer below links it has good explanation on auto layout using size class.
http://mathewsanders.com/designing-adaptive-layouts-for-iphone-6-plus/
http://mobileoop.com/how-to-use-auto-layout-in-xcode-6-for-ios-7-and-8-development
Hope it will be helpful in solving your issue.

Resizing the superview according to the subviews

I have 3 subviews(UILabel, UIImageview, UIButton) to be laid out on a container view. All the subviews are laid out using visual format language (VFL). The subview have padding from the leading , top edges etc. The content of the subview are dynamic so their sizes changes all the time. i want to resize the superview(container view) to exactly fit all the subviews. Is this possible by auto layout? i have seen some of the link here which suggest intrinsic size which i am not able to understand. can someone suggest a better way to achieve this.
Yes, it's possible. If you plan to resize the superview according to subview content, then intrinsic content size is the way to go.
The ever excellent Ray Wenderlich site has a tutorial that covers this well. It's Beginning Auto Layout in iOS 6: Part 2/2:
Intrinsic Content Size
Before Auto Layout, you always had to tell buttons and other controls
how big they should be, either by setting their frame or bounds
properties or by resizing them in Interface Builder. But it turns out
that most controls are perfectly capable of determining how much space
they need, based on their content.
A label knows how wide and tall it is because it knows the length of
the text that has been set on it, as well as the font size for that
text. Likewise for a button, which might combine the text with a
background image and some padding for the rounded corners.
The same is true for segmented controls, progress bars, and most other
controls, although some may only have a predetermined height but an
unknown width.
This is known as the intrinsic content size, and it is an important
concept in Auto Layout. You have already seen it in action with the
buttons. Auto Layout asks your controls how big they need to be and
lays out the screen based on that information.
It is possible.
In my case, I wanted to give rounded corners to segmented control. For that, I embedded segmented control in UIView. Now I was required to resize that container view as per size of segmented control.
I gave only following constraint and everything was taken care itself.
(1) Chose container view and give it X and Y constraints.
Leading space to Super view.
Top space to Super view.
(2) Chose container view and give Leading | Trailing | Top | Bottom constraint.
Leading space to segmented control.
Top space to segmented control.
Trailing space to segmented control.
Bottom space to segmented control.
(3) Chose segmented control and give it Height and Width constraints.
Height : 30 // Whatever
Width : 250 // Whatever
Now if I change the height and width of my segmented control, it automatically adjust container view's size (super-view of segmented control).

Resources