Open nerdycat opened 8 years ago
(void)viewDidLoad { [super viewDidLoad];
UILabel label1 = [UILabel new]; UILabel label2 = [UILabel new]; label1.text = @"Some long text!!!"; label2.text = @"ABC";
OAStackView *sv = [[OAStackView alloc] initWithArrangedSubviews:@[label1, label2]]; sv.translatesAutoresizingMaskIntoConstraints = NO; sv.axis = UILayoutConstraintAxisHorizontal; sv.alignment = OAStackViewAlignmentTop; sv.distribution = OAStackViewDistributionEqualSpacing;
[self.view addSubview:sv];
[sv.topAnchor constraintEqualToAnchor:self.view.topAnchor constant:50].active = YES; [sv.leftAnchor constraintEqualToAnchor:self.view.leftAnchor constant:10].active = YES; [sv.rightAnchor constraintEqualToAnchor:self.view.rightAnchor constant:-10].active = YES;
UILabel label3 = [UILabel new]; UILabel label4 = [UILabel new]; label3.text = @"Some long text!!!"; label4.text = @"ABC";
UIStackView *sv2 = [[UIStackView alloc] initWithArrangedSubviews:@[label3, label4]]; sv2.translatesAutoresizingMaskIntoConstraints = NO; sv2.axis = UILayoutConstraintAxisHorizontal; sv2.alignment = OAStackViewAlignmentTop; sv2.distribution = OAStackViewDistributionEqualSpacing;
[self.view addSubview:sv2];
[sv2.topAnchor constraintEqualToAnchor:sv.bottomAnchor constant:50].active = YES; [sv2.leftAnchor constraintEqualToAnchor:self.view.leftAnchor constant:10].active = YES; [sv2.rightAnchor constraintEqualToAnchor:self.view.rightAnchor constant:-10].active = YES; }
The codes are very similar, one for OAStackView, one for UIStackView. The result is different, the label1 get clipped and label3 is fine.
(void)viewDidLoad { [super viewDidLoad];
UILabel label1 = [UILabel new]; UILabel label2 = [UILabel new]; label1.text = @"Some long text!!!"; label2.text = @"ABC";
OAStackView *sv = [[OAStackView alloc] initWithArrangedSubviews:@[label1, label2]]; sv.translatesAutoresizingMaskIntoConstraints = NO; sv.axis = UILayoutConstraintAxisHorizontal; sv.alignment = OAStackViewAlignmentTop; sv.distribution = OAStackViewDistributionEqualSpacing;
[self.view addSubview:sv];
[sv.topAnchor constraintEqualToAnchor:self.view.topAnchor constant:50].active = YES; [sv.leftAnchor constraintEqualToAnchor:self.view.leftAnchor constant:10].active = YES; [sv.rightAnchor constraintEqualToAnchor:self.view.rightAnchor constant:-10].active = YES;
UILabel label3 = [UILabel new]; UILabel label4 = [UILabel new]; label3.text = @"Some long text!!!"; label4.text = @"ABC";
UIStackView *sv2 = [[UIStackView alloc] initWithArrangedSubviews:@[label3, label4]]; sv2.translatesAutoresizingMaskIntoConstraints = NO; sv2.axis = UILayoutConstraintAxisHorizontal; sv2.alignment = OAStackViewAlignmentTop; sv2.distribution = OAStackViewDistributionEqualSpacing;
[self.view addSubview:sv2];
[sv2.topAnchor constraintEqualToAnchor:sv.bottomAnchor constant:50].active = YES; [sv2.leftAnchor constraintEqualToAnchor:self.view.leftAnchor constant:10].active = YES; [sv2.rightAnchor constraintEqualToAnchor:self.view.rightAnchor constant:-10].active = YES; }
The codes are very similar, one for OAStackView, one for UIStackView. The result is different, the label1 get clipped and label3 is fine.