0

I am having a problem where a UIButton is changingit's width if I add anotherbuttoninside the sameview`.

This is how it looks without the 2nd button:

enter image description here

and this is how it looks if I constrain the 2nd button (title: "Wishlist?") inside the same view:

enter image description here

This is how I create the rounded image button:

let wishButton: UIButton = {
    let v = UIButton()
    v.setBackgroundImage(UIImage(named: "wishButton"), for: .normal)
    v.translatesAutoresizingMaskIntoConstraints = false
    v.addTarget(self, action: #selector(wishButtonTapped), for: .touchUpInside)
    v.contentVerticalAlignment = .fill
    v.contentHorizontalAlignment = .fill
    return v
}()

// constrain wishButton
    wishButton.centerXAnchor.constraint(equalTo: popUpView.centerXAnchor).isActive = true
    wishButton.centerYAnchor.constraint(equalTo: popUpView.centerYAnchor, constant: 70).isActive = true
    wishButton.heightAnchor.constraint(equalToConstant: 72).isActive = true
    wishButton.widthAnchor.constraint(equalToConstant: 72).isActive = true

2nd button with title:

let dropDownButton: dropDownBtn = {
    let v = dropDownBtn()
    v.setTitle("Wishlist?", for: .normal)
    v.translatesAutoresizingMaskIntoConstraints = false
    return v
}()

        // constrain dropDownButton
    dropDownButton.centerXAnchor.constraint(equalTo: popUpView.centerXAnchor).isActive = true
    dropDownButton.centerYAnchor.constraint(equalTo: popUpView.centerYAnchor).isActive = true
    wishButton.heightAnchor.constraint(equalToConstant: 100).isActive = true
    wishButton.widthAnchor.constraint(equalToConstant: 40).isActive = true
1
  • IDK how you center them X and Y and gives this look Commented Dec 14, 2019 at 18:35

1 Answer 1

1

You have conflicts

wishButton.heightAnchor.constraint(equalToConstant: 72).isActive = true
wishButton.widthAnchor.constraint(equalToConstant: 72).isActive = true

and

wishButton.heightAnchor.constraint(equalToConstant: 100).isActive = true
wishButton.widthAnchor.constraint(equalToConstant: 40).isActive = true

You may mean

dropDownButton.heightAnchor.constraint(equalToConstant: 100).isActive = true
dropDownButton.widthAnchor.constraint(equalToConstant: 40).isActive = true
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.