tech_human
tech_human

Reputation: 7110

How to vertically align UIButton text with UILabel text?

I have a table view cell and I have a label and button vertically aligned in vertical stack view. I want the text on UIButton to start right below UILabel. But even if I set the contentHorizontalAlignment on button to left, it still doesn't start from right below the label. I want 'S' of 'Select' right below 'L' of 'Label'. How do I achieve it?

Code:

self.selectPersonButton.contentHorizontalAlignment = .left

enter image description here

enter image description here

Upvotes: 0

Views: 626

Answers (1)

igitgor
igitgor

Reputation: 66

By default buttons has content insets, you must change them to custom, to be able to set you own if you need.

enter image description here

in the picture shown the place of that configuration, change it to custom and set all insets to 0 , like in picture below.

enter image description here

Everything will work as you expect.

As an information starting from iOS 15 Apple added new way of configuring buttons, apple document Button.Configuration

Upvotes: 0

Related Questions