Advertisement
Don_Mag

Untitled

Dec 5th, 2021
2,492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. - (void)viewDidLoad {
  3.     [super viewDidLoad];
  4.    
  5.     UIStackView *stack = [UIStackView new];
  6.     stack.distribution = UIStackViewDistributionFillEqually;
  7.     stack.spacing = 8;
  8.  
  9.     UILabel *v1 = [UILabel new];
  10.     v1.backgroundColor = [UIColor cyanColor];
  11.     v1.textAlignment = NSTextAlignmentCenter;
  12.     v1.numberOfLines = 0;
  13.     v1.text = @"One Line";
  14.    
  15.     UILabel *v2 = [UILabel new];
  16.     v2.backgroundColor = [UIColor greenColor];
  17.     v2.textAlignment = NSTextAlignmentCenter;
  18.     v2.numberOfLines = 0;
  19.     v2.text = @"Lots of text to force the label to wrap onto multiple lines.";
  20.    
  21.     [stack addArrangedSubview:v1];
  22.     [stack addArrangedSubview:v2];
  23.    
  24.     stack.translatesAutoresizingMaskIntoConstraints = NO;
  25.     [self.view addSubview:stack];
  26.    
  27.     [NSLayoutConstraint activateConstraints:@[
  28.  
  29.         [stack.leadingAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.leadingAnchor constant:20.0],
  30.         [stack.trailingAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.trailingAnchor constant:-20.0],
  31.         [stack.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor constant:-20.0],
  32.        
  33.     ]];
  34.  
  35. }
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement