views:

569

answers:

1

I would like to implement a view (it will actually be going into the footer of a UITableView) that implements 1-3 buttons. I would like the layout of these buttons (and the size of the buttons themselves) to change depending on which ones are showing. An example of almost the exact behavior I would want is at the bottom of the Info screen in the Contacts application when you are looking at a specific contact ("Add to Favorites" disappears when it is clicked, and the other buttons expand to take up the available space in a nice animation).

As I'm running through the different layout scenarios, I'm hard coding all these values and I just think... "this is NOT the way I'm supposed to be doing this."

It even APPEARS that Interface Builder has some features that may do this for me in the ruler tab, but I'll be darned if I can figure out how they work (if they work) on the phone.

Does anyone have any suggestions, or a tutorial online that I could look at to point me in the right direction?

Thanks much.

A: 

You could take a look at Stanford cs193p classes

I think there is a demo in one of the lessons/example where they programaticaly set the autoresize of the buttons and some other where they animate the view. you can also make the view set dynamically the width of each of its subview to (ownWidth/numberofSubView),the same for the positon of each elements.

[edit] like that ? it's not "dynamic" yet, but you've got the idea you can increase/decrease numberOfbuttons when "adding/removing" a button then reset the new frame of all the subviews

- (void)loadView
{

UIView *view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
view.backgroundColor = [UIColor lightGrayColor];
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

int numberOfbuttons = 2;
CGFloat buttonsLegth = (-20+view.bounds.size.width)/numberOfbuttons-20;
for(int i=0;i<numberOfbuttons;i++){
 CGRect buttonFrame = CGRectMake(0, 0, buttonsLegth, 37);
 buttonFrame.origin.x = (buttonFrame.size.width+20)*i + 20.0;
 buttonFrame.origin.y =  20.0;
 UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; // Autoreleased
 button.frame = buttonFrame;
 [button setTitle:@"Done" forState:UIControlStateNormal];
 [view addSubview:button];
    }
self.view = view;
[view release];
}
Matt
Evan does mention the autoresizing mask settings for UIView in lesson 6. It's not exactly what I am looking for. My view never changes size or shape. The layout of the buttons within the view changes, depending on which buttons are IN the view.
mmc