title: Swift auto layouts change button position when some buttons are hidden
body: <p>I have custom <code>UICollectionViewCell</code> as <code>TaskCell</code> in which I have added 4 buttons.
  All the Buttons are added programatically using auto layouts.</p>
  
  <p>Now when I hide some buttons then i want the other remaining buttons to take a place of hidden buttons. Check following images.</p>
  
  <p><a href="https://i.stack.imgur.com/3UelF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3UelF.png" alt="enter image description here"></a></p>
  
  <p>Here you can see 4 buttons align to the right side by using trailingAnchors. 
  Now if I hide the last two buttons which is a Rating and Delete then I want the remaining two buttons to shift to the right and take the place of rating and delete button.</p>
  
  <p>Following image shows other buttons remain at same place when I hide rating and delete buttons.</p>
  
  <p>What can be the best way to do this ?</p>
  
  <p>I know one way where we have to store the trailingAnchors and set it's active property according to our condition.</p>
  
  <p>like following</p>
  
  <p><a href="https://i.stack.imgur.com/PvBw6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PvBw6.png" alt="enter image description here"></a></p>
  
  <pre><code>var deleteTrailingAnchor: NSLayoutConstraint?
  
  deleteTrailingAnchor = deleteButton.trailingAnchor.constraint(equalTo: buttonContainer.trailingAnchor, constant: -8)
  
   deleteTrailingAnchor?.isActive = true
  </code></pre>
  
  <p>Now we have to manage <code>deleteTrailingAnchor</code> according to our need.</p>
  
  <p>Is there any better way to solve this issue using <code>AutoLayouts</code>.</p>
  
  <p>Thank you for help.</p>