When is sizethatfits called
Asked By: Vadoff. Answered By: Vadoff. Sticky search bar and section header behavior similar to native Contacts app. Ask Question. Asked 9 years, 2 months ago. Active 7 years, 11 months ago. Viewed 5k times. Pwner Pwner 3, 5 5 gold badges 37 37 silver badges 66 66 bronze badges. Did you ever resolve this issue? Add a comment. Active Oldest Votes.
Johannes Fahrenkrug Johannes Fahrenkrug Verbose: I don't have time for a full answer, but I think the proper solution here is to implement updateConstraints. From testing on iOS 8. This gives the AL system all that it needs to determine the size, without actually having to lay things out.
TomSwift TomSwift Patrick Goley Patrick Goley 5, 18 18 silver badges 40 40 bronze badges. The documentation suggests that overriding intrinsicContentSize may not be the best way to achieve what you want to achieve. As you've observed, from the UIView class reference:. Setting this property allows a custom view to communicate to the layout system what size it would like to be based on its content. MyView's bounds are not set until after its intrinsicContentSize has been requested, and in an auto layout context are not guaranteed to have been set at any time before layoutSubviews is called.
There is a way to work around that and pass a width to your custom view for use in intrinsicContentSize , however, which I've included as the second option in this answer. First, in the absence of auto layout, configure MyView and its label subview to size and resize themselves appropriately:. MyView will now size itself according to the size of its label subview, and the label will be sized according to the width of its superview because of its.
I added them in IB, and made IBOutlets to their constraints they have to the left side of the view that's what the system gave me, it could have been to the right side -- it doesn't matter since you just delete them anyway. If you are making the dots in code, you wouldn't need to do this. Asked 5 Months ago Answers: 5 Viewed 67 times. To make it super simple I'll go with an example, let's assume I need an UIView subclass that has an image icon and a multiline label; the behaviour I want is that the height of my view changes with the height of the label to fit the text inside , also, I'm laying it out with Interface builder, so I have something like this: with some constraints that give fixed width and height to the image view, and fixed width and position relative to the image view to the label: Now, if I set some text to the label, I want the view to be resized in height to fit it properly, or remain with the same height it has in the xib.
I don't think you need to define an intrinsicContentSize. Here's two reasons to think that: When the Auto Layout documentation discusses intrinsicContentSize , it refers to it as relevant to "leaf-views" like buttons or labels where a size can be computed purely based on their content.
As the documentation says, you should not call these methods yourself. This can happen multiple times while your app is running if your view controller has to unload its view in response to memory pressure, another behavior you get for 'free' and that you don't want to call yourself If these methods are not being called in your view controller, then there must be something wrong with how you are presenting this view controller, which is preventing the framework code in UIViewController from calling these methods.
Before you attempt to fix that bug, though, you should remove these from your code: [self loadView] [self viewDidLoad] And then in your own implementation of viewDidLoad , you will want to call the superclass' implementation with [super viewDidLoad] Remember that in loadView your only responsibility to set self. Hope that helps. I also had this problem and found the solution. Below is the code which will work for iOS 8.
I have tested it on iOS 7 and 8. Dimitre Novatchev.
0コメント