How to get started in layouting subviews manually?
For testing and practicing I would like to implement a real simple layout manager which just aligns one control next to the other as long as there is space to the right and then goes to next line.
For instance: have a UIView and keep on adding UIButtons with random widths as subviews. one "line" is 40 pixels high. First button is added at (0,0), next one at (120, 0), next one is too wide and will go to (0,40), next one to (80,40) and so on.
The question is not how to do that but which methods of MonoTouch are involved? My guess would be to override LayoutSubViews() and in there implement my logic to align the controls - is that correct? 开发者_Go百科Do I have to call base.LayoutSubViews()? Do I have to override anything else? It should of course realign as buttons get removed or added and also if the view itself changes in size. Do I have to touch SizeToFit(), too?
René
You should checkout the MonoTouch docs for UIView. Your guess is right in calling LayoutSubViews to position and align your subviews and you'll most likely end up overriding the Draw method on your view. I think the TweetStation example does a bit of manual view drawing. You might want to check that for ideas.
精彩评论