1

I have a set of UIButtons with identical diameters but diffrent length titles embedded in the view.

When I select the buttons the selection area covers only the title meaning that they look like they have different sizes, see image below. enter image description here

How do I set in Swift the same size of the selected area?

EDIT:

The buttons are of the same width (see image below) and are distributed using autolayout. enter image description here

Moreover when I set the background of the buttons to some color it does fill the whole button; see below enter image description here

So only the is Selected attribute is causing the problem.

kwicher
  • 2,092
  • 1
  • 19
  • 28
  • You could set the frame (== hit area) of the button. But you should create background image yourself, or add UILabel on this button (do not forget set label.isUserInteractionEnabled = true) – Anton Belousov May 31 '17 at 23:13
  • Are these button laid out in a horizontal layout ? By default, UIButton adjusts its size just enough to fit the text. You can try setting buttons' layout constraints in such a way that all buttons have equal widths and are aligned horizontally along same axis. – tek3 May 31 '17 at 23:41
  • did you get the solution ? – nikdange_me Oct 22 '17 at 17:39
  • no I have not got – kwicher Oct 24 '17 at 15:03

2 Answers2

-1

You can embed these buttons in a Horizontal UIStackView, and set the Distribution to fill Equally.

EricXuan
  • 387
  • 1
  • 2
  • 11
-1

if you want same size of selection area then you can use Autolayout..

refer link same size of the selected area

Foolish
  • 159
  • 10