UIStackView简单使用

来源:互联网 发布:淘宝内衣真人秀视频 编辑:程序博客网 时间:2024/06/11 14:10

 NSMutableArray * array1 = [[NSMutableArrayalloc]init];

    for (int i =0 ; i<5; i++) {

        UIView * view = [[UIViewalloc]init];

        view.backgroundColor = [UIColorcolorWithRed:arc4random()%255/255.0green:arc4random()%255/255.0blue:arc4random()%255/255.0alpha:1];

        [array1 addObject:view];

    }

    

    _stackView1 = [[UIStackViewalloc]initWithArrangedSubviews:array1];

    [_stackView1setFrame:CGRectMake(0,20, [UIScreenmainScreen].bounds.size.width,200)];

    [_stackView1setAxis:UILayoutConstraintAxisHorizontal];

    [_stackView1setSpacing:10];

    [_stackView1setDistribution:UIStackViewDistributionFillProportionally];

    [_stackView1setAlignment:UIStackViewAlignmentFill];

    [self.viewaddSubview:_stackView1];



    NSMutableArray * array2 = [[NSMutableArrayalloc]init];

    for (int i =0 ; i<5; i++) {

        UIView * view = [[UIViewalloc]init];

        view.backgroundColor = [UIColorcolorWithRed:arc4random()%255/255.0green:arc4random()%255/255.0blue:arc4random()%255/255.0alpha:1];

        [array2 addObject:view];

    }

    _stackView2 = [[UIStackViewalloc]initWithArrangedSubviews:array2];

    [_stackView2setFrame:CGRectMake(0,250, [UIScreenmainScreen].bounds.size.width,200)];

    _stackView2.axis =UILayoutConstraintAxisVertical;

    _stackView2.distribution =UIStackViewDistributionFillProportionally;

    _stackView2.alignment =UIStackViewAlignmentFill;

    _stackView2.spacing =10;

    [self.viewaddSubview:_stackView2];


0 0
原创粉丝点击