Question about UIView sizeThatFits

Possible duplicate:
iPhone - input parameter for sizeThatFits method for UIView

In particular, what is his argument? The documentation says that this is the current size of the receiver, but the view can always use self.bounds.size , so that doesn't make sense.

Is this available space? In other words, the parent asks the child, "given that there is a free space of X x Y points, how much do you want to be big?"

+4
source share
4 answers

I just think the document is wrong when it says "Current receiver size." This is only a precedent, but there are others: for example, if you want the view to return the best size, taking into account an arbitrary size, you call this method, passing an arbitrary size as a parameter.

Is this available space? In other words, the parent asks the child, "given that there is a free space of X x Y points, how much do you want to be big?"

Yes, you have an idea, but do not limit the value of the argument to "available space." This is just an arbitrary size, which may or may not fit the available space. It depends on how you use this method. However, it is assumed that the view always returns what it thinks is its best size (the size that best matches its views) if it should match the size passed as an argument.

Look here, this should answer your question: iPhone is the input parameter for the sizeThatFits method for UIView

+7
source

To a large extent, that’s it. Classes such as UIPickerView and UILabel have content that works best with certain sizes, and as such return these specific sizes, rather than the more common bounds size.

+2
source

Just sizeThatFit: the method should be overridden with the new CGSize, and the sizeToFit method calls sizeThatFit to resize.

0
source

sizeThatFits can be used when the supervisor puts its children.

Let's say you have a 300-pixel supervisor, and you still don't know how tall it will be - the height will be based on the sum of the children’s heights. In this case, the supervisor will have a sizeToFit representing the remaining free space, which will differ from the boundaries of the supervisor.

-1
source

All Articles