Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

question about UIView's sizeThatFits [duplicate]

Possible Duplicate:
iPhone — the input parameter to UIView's sizeThatFits method

Specifically, what's its argument supposed to be? The documentation says that it's the receiver's current size, but a view can always use self.bounds.size, so that doesn't make sense.

Is it supposed to be the available space? In other words, is the parent asking the child, "given that there's available space of X x Y points, how big do you want to be?".

like image 382
Kartick Vaddadi Avatar asked Apr 29 '11 05:04

Kartick Vaddadi


2 Answers

I simply believe the doc is wrong when it says "The current size of the receiver". It is only a use case but there are others: for example if you want the view to return its very best size given an arbitrary size you will call this method passing your arbitrary size as the parameter.

Is it supposed to be the available space? In other words, is the parent asking the child, "given that there's available space of X x Y points, how big do you want to be?".

Yes, you've got the idea BUT don't restrict the meaning of the argument to the "available space". It's just an arbitrary size that may or not correspond to an available space. It depends on how you are using the method. However the view is supposed to always return what it considers to be its best size (the size that best fits its subviews) if it has to fit into the size passed as an argument.

Look here, this should answer your question: iPhone -- the input parameter to UIView's sizeThatFits method

like image 119
thomas.g Avatar answered Oct 21 '22 14:10

thomas.g


Pretty much exactly that. Classes like UIPickerView and UILabel have content that works best at particular sizes, and as such they return those specific sizes rather than the more general bounds size.

like image 33
Noah Witherspoon Avatar answered Oct 21 '22 12:10

Noah Witherspoon