停靠模式:子视图自适应父视图长度宽度左边距右边距上下边距

来源:互联网 发布:淘宝客如何生成淘口令 编辑:程序博客网 时间:2024/04/29 20:22

    UIView *v = [[UIViewalloc] initWithFrame:CGRectMake(0,20, 200, 200)];

    v.tag =100;

    v.backgroundColor = [UIColororangeColor];

    [self.windowaddSubview:v];

    [vrelease];

    

    UIView *v1 = [[UIViewalloc] initWithFrame:CGRectMake(50,50, 50, 50)];

    v1.backgroundColor = [UIColorblueColor];

    //停靠模式当父视图发生变化时 子视图也会发生相应的变化

    v1.autoresizingMask =UIViewAutoresizingFlexibleHeight| UIViewAutoresizingFlexibleWidth;

    [vaddSubview:v1];

    [v1release];

    

    UIButton *b = [UIButtonbuttonWithType:UIButtonTypeCustom];

    b.frame =CGRectMake(0,320, 100, 30);

    [b setTitle:@"click"forState:UIControlStateNormal];

    [b addTarget:selfaction:@selector(click)forControlEvents:UIControlEventTouchUpInside];

    [self.windowaddSubview:b];

    

    

    return YES;

}


bool flag =YES;

-(void)click

{

   UIView *v = [self.windowviewWithTag:100];

   if (flag) {

        v.frame =CGRectMake(0,20, 300, 300);

    }else{

        v.frame =CGRectMake(0,20, 200, 200);

    }

   flag = !flag;

}

0 0
原创粉丝点击