Get the width of a UIBarButtonItem

后端 未结 5 843
-上瘾入骨i
-上瘾入骨i 2020-12-05 05:14

I\'m trying to get the width of a UIBarButtonItem.

This doesn\'t work:

barbuttonitem.customView.frame.size.width

And t

5条回答
  •  星月不相逢
    2020-12-05 06:18

    In case you are interested in the width on one particular item, the easiest way is to have two IBOutlets: one for the button and the other for the corresponding bar button item. Instead of reading the bar button item width, you will read the button width.

    This approach, of course, will not work if you want e.g. to sum the widths in a loop. (By the way, the 1st button starts at x=12 and the distance between two buttons is 10, unless you do something tricky.) Of course, you can have two arrays, but this is just cumbersome.

提交回复
热议问题