简体   繁体   中英

Auto resize UIButton at run time.

I want to resize the existing UIButtons when i add a button at run time, just like safari iPad adds the tabs and all the tabs get resized when new tab get added. and i want to do it either using aotolayout or autoresizingmask.

Thanks

Create a mutable collection for keeping the references to the buttons. If you need to have them ordered somehow, create NSMutableArray, if not, create NSMutableSet. In the header file declare the ivar like NSMutableSet buttonsSet, then in the class implementation:

float x=0,y=0;
buttonsSet = [[NSMutableSet alloc] init];
for( NSMutableDictionary *dict in places) {
    NSLog(@"x: %f",x);
    x=x+25;
    y=y+25;// Vary these depending on where you want the buttons to be
    UIButton *button = [[[UIButton alloc] initWithFrame:CGRectMake(x,y,25,25)] autorelease];
    button.backgroundColor=[UIColor redColor];
    [buttonsSet addObject:button];
    [self addSubview:button];
}

This should do what you are looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM