代码预览:
- (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];
}
网友评论