美文网首页
iOS UIStackView 代码实现

iOS UIStackView 代码实现

作者: 达_Ambition | 来源:发表于2018-08-31 11:34 被阅读13次
    参考原文:UIStackView学习分享, 纯代码实现
    代码预览:
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        containerView = [[UIStackView alloc] initWithFrame:CGRectMake(0, 100, ScreenWidth, 200)];
        containerView.axis = UILayoutConstraintAxisHorizontal;
        containerView.distribution = UIStackViewDistributionFillEqually;
        containerView.spacing = 10;
        containerView.alignment = UIStackViewAlignmentFill;
        
        for (NSInteger i = 0; i < 4; i++) {
            UIView *view = [[UIView alloc] init];
            view.backgroundColor = [UIColor colorWithRed:random()%256/255.0 green:random()%256/255.0 blue:random()%256/255.0 alpha:1];
            [containerView addArrangedSubview:view];
        }
        
        [self.view addSubview:containerView];
    }
    
    

    相关文章

      网友评论

          本文标题:iOS UIStackView 代码实现

          本文链接:https://www.haomeiwen.com/subject/uxdswftx.html