1

I have a custom UIView using for Custom UITabBar whose height is fixed 50 and I am adding a stackview for each button but I need middle button height should be more.

let view: UIView = views[3]
view.heightAnchor.equalToConstant(100.0).isActive = true

let stackView: UIStackView = UIStackView(arrangedSubviews: [views])
     stackView.translatesAutoresizingMaskIntoConstraints = false
     stackView.axis = .horizontal
     stackView.distribution = .fillEqually
     addSubview(stackView)
     stackView.topAnchor.constraint(equalTo: topAnchor).isActive = true
     stackView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
     stackView.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
     stackView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true

How can I change the height of a particular view inside the stackView?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
AppleBee
  • 452
  • 3
  • 16

2 Answers2

0

I may not understand your problem but you can change anyviews height using constraints as you have already done. It is same when the view is subview of a stackview. Stackview updates it's size to satisfy its constraint. You have to have a reference to height constraint of the view inside stackview. Then you can change it whenever need to. Also it would be nice to set stackviews alignment property to have desired look.

let heightConstraint = view.heightAnchor.equalToConstant(100.0)
heightConstraint.isActive = true
.
.
.
heightConstraint.constant = 150
plymr
  • 45
  • 7
0

You want to change the Alignment property of the stack view...

Assuming 5 views, each with a height constraint of 60, and you want the 4th view (views[3]) to have a height of 100.

StackView Alignment Top:

enter image description here

StackView Alignment Center:

enter image description here

StackView Alignment Bottom:

enter image description here

DonMag
  • 69,424
  • 5
  • 50
  • 86